I’m doing a chronometer and everything is doing well and work it, however there is a little problem, It’s happenning a delay of 2 second when I click and call the function start(). After delay, chronometer starts without problems.
The code is right here:
let ss = 00;
let mm = 00;
let hh = 00;
let tempo = 1000;
let cron;
function timer() {
let padrao = (`${hh <10? '0' + hh: hh}:${mm < 10? '0' + mm : mm}:${ss < 10? '0' + ss : ss}`);
document.getElementById('stopWatch').innerText = padrao;
ss++;
if (ss == 60) {
ss = 0;
mm++
} else if (mm == 60) {
mm = 0;
hh++
}
}
function start() {
cron = setInterval(() => {timer();}, tempo);
document.getElementById("run").disabled = true;
}
function pause() {
clearInterval(cron);
document.getElementById("run").disabled = false;
}
function reset() {
clearInterval(cron);
ss = 00;
mm = 00;
hh = 00;
document.getElementById('stopWatch').innerText = '00:00:00';
document.getElementById("run").disabled = false;
}
strong text