0
I’m trying to make a counter work when I click a button, it turns out that when a button is clicked more than once the counter starts to decrement too fast.
Source code:
var pomodoro = document.querySelector('#btn1');
var count = new Number();
function start () {
if((count -1) >= 0) {
count = count - 1;
sessao.innerText = count;
setTimeout('start()', 1000);
}
}
pomodoro.onclick = function () {
count = 1500;
return start();
}
Here’s a 30-second video link showing how the code is working.
So you want it to be called once and it can stop ? (because it happens such behavior quoted: the code is being called several times and then it ends up having the increment several times and your impression is that this is happening too fast). What is the expected behavior for your code
– novic
Whoa, Virgilio, good morning. My intention is that, when clicking again, it restarts the contagion normally, without decreasing too fast, as is happening there.
– Antônio Matheus