I have this JavaScript code that counts down the number and I would like the counter to display two digits when the number is less than 10 (09, 08, ...)
(function test() {
setTimeout(function() {
$('#id').text(Number($('#id').text()) - 1);
test();
}, 1000);
})();
//more flexible and modular version
function myTimer(elem, maxtime, indexTime ) {
var i = 0;
test();
function test() {
setTimeout(function () {
elem.text(i);
i++;
if (i < maxtime) {
test();
} else {
console.log('end');
return false;
}
}, indexTime);
}
}