I'm trying to create a chronometer, It works well when I don't add the typical zeroes before the 1 digit numbers, but when trying to create a logic that removes the zero it makes my code working not properly.
Please, run this working snippet:
var n = 0;
var m = 0;
var h = 0;
var n = ( n < 2 ) ? n = "0" + 2 : n.slice(-2) ;
var scrubberCounter = document.getElementById("scrubberCounter");
setInterval(function () {
if(n.toString().length < 2 && m.toString().length < 2){
scrubberCounter.innerHTML = h + ":" + "0" + m + ":" + "0" + n;
}else{
scrubberCounter.innerHTML = h + ":" + m + ":" +n;
}
n++;
if (n ===20) {
if (m < 20) {
m++;
} else {
m = 0;
h++;
}
n = 0;
}
}, 300);
<table style='border: 1px solid orange; background: white;'><tr><td><font color='red' id='scrubberCounter'></font></td></tr></table>Can you please lend me a hand? Thank you so much.
Aucun commentaire:
Enregistrer un commentaire