I am building a few things and one of them is a countdown timer, the countdown will never be over an hour so all I need to do is countdown minutes and seconds.
I have it
setInterval
returns an identity you can use later to clearInterval
:
var interval = setInterval(function() {
/* snip */
$('span').html(minutes + ':' + seconds);
if (parseInt(minutes, 10) == 0 && parseInt(seconds, 10) == 0)
clearInterval(interval);
}, 1000);
And, to avoid the ever-increasing minutes -- 00000001:42
-- either:
length.minutes
to minutes.length
in your prefix test.var minutes = parseInt(timer[0], 10);
-- and just test if (minutes < 10) ...
.Taking option #2, here's an update: http://jsfiddle.net/BH8q9/