1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

1 point every hour

Discussion in 'Programming' started by marly, Jul 20, 2017.

  1. marly

    marly Junior Member

    Joined:
    Nov 4, 2010
    Messages:
    172
    Likes Received:
    29
    Gender:
    Male
    Location:
    Netherlands
    Trying to implement a function to my site that, every hour your logged in, you get 1 point.
    Or you have an image next to login that changes to "receive point" every hour.
    This to reward dedication.
    I've studies some jquery, but have yet to find a solid solution.
    Any point in the right direction, you rock!
     
  2. Sergey Yermak

    Sergey Yermak Newbie

    Joined:
    Mar 12, 2016
    Messages:
    29
    Likes Received:
    3
    Gender:
    Male
    Occupation:
    Node.js
    I think one way to do it is to send ajax request to some server script periodically.
    And in that script you can compare last time this request was sent by user, and make decisions from the timespans between this requests.
     
  3. Elifont

    Elifont Newbie

    Joined:
    Jul 2, 2017
    Messages:
    30
    Likes Received:
    0
    Code:
    function Main() {
        var time;   
        time = 0;
    
        var points;   
        points = 0;
    
        for (time = 0 ; time <= 59 ; time += 1) {
            points = points + 1;
            output("points: " + points);
            output(points);
        }
    }
    
    
    
    function output (text) {
        //window.alert(text);
        console.log(text);
    }
    
    

    Not tested the above but I believe this simple code I written should achieve in the simplistic sense what you are trying to do and get you started in the right direction.

    As in respect of time in Javascript you can use EPOCH time and calculate manually to do it on an hour basis (my code does it for 60 seconds) or you can use this really easy JS library, JS is just as good as Jquery in my opinion, especially for doing something simple like this there is not much point in jquery you can achieve the same perhaps easier with javascript, check out the time library here: momentjs.com I can't post links yet I think so apologies for that.
     
  4. marly

    marly Junior Member

    Joined:
    Nov 4, 2010
    Messages:
    172
    Likes Received:
    29
    Gender:
    Male
    Location:
    Netherlands
    Thanks so much for your input will try and implement this!! Will let you know how it worked.
     
  5. Kode

    Kode Junior Member

    Joined:
    Sep 21, 2016
    Messages:
    113
    Likes Received:
    21
    Gender:
    Male
    I did something like this. It was logging work hours. Like Sergey Yermak said used Ajax to update your server. But on your client side, use set_interval as the timer. You also have to keep track of the timers on the server-side. Otherwise I can just launch multiple tabs and game the system. ;D
     
  6. Elifont

    Elifont Newbie

    Joined:
    Jul 2, 2017
    Messages:
    30
    Likes Received:
    0
    It works, just it prints to console currently so you need to assign it to appropiate class, div or whatever how your website works in terms of outputs.