javascript - Function returning NaN and not counting properly -


i trying create counter counts time down returning nan , not counting down.

i have more 1 counters. 1 counts-down, counts-up until stoptime , 1 more counts after stoptime, overtime. 1 returning nan , others not working or counting.

  function fixintegers(integer) {       if (integer < 0) integer = 0;       if (integer < 10) return '0' + integer;       return '' + integer;   }    function timecount(difference) {       var toreturn = {           weeks: 0,           days: 0,           hours: 0,           minutes: 0,           seconds: 0       };       toreturn.seconds = fixintegers(difference % 60);       difference = math.floor(difference / 60);        toreturn.minutes = fixintegers(difference % 60);       difference = math.floor(difference / 60);        toreturn.hours = fixintegers(difference % 24);       difference = math.floor(difference / 24);        toreturn.days = fixintegers(difference % 7);       difference = math.floor(difference / 7);        toreturn.weeks = fixintegers(difference);       return toreturn;   }      var inthisdiv = $(this).parents().eq(0); // parent    var nowtime = new date(); //time   var starttime = new date(inthisdiv.find('.starttime').val());   var stoptime = new date(inthisdiv.find('.stoptime').val());    if (starttime < nowtime && nowtime < stoptime) {       var diff = timecount(math.floor((nowtime - starttime) / 1000));       output = (parseint(diff, 10) + 2);       console.log(output.weeks);   } else if (stoptime < nowtime) {       var output = timecount(math.floor((stoptime - starttime) / 1000));   } else if (nowtime > stoptime) {       var output = timecount(math.floor((nowtime - stoptime) / 1000));   } else {       var output = timecount(math.floor((stoptime - nowtime) / 1000));   }   console.log(output.weeks); 

thanks in advance. here fiddle: http://jsfiddle.net/aljt9/ edit: added html new fiddle: http://jsfiddle.net/aljt9/4/

you're js looking , element non-existent (at least in fiddle)

  var starttime = new date(inthisdiv.find('.starttime').val());   var stoptime = new date(inthisdiv.find('.stoptime').val()); 

you need make sure these elements in dom , make sure have value.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -