0
Hello,
I have created a countdown function, which is working correctly. The only problem is that I can’t stop it. I made all kinds of adaptation with Return and clearInterval(), she stops for a second and then immediately back to execution.
This is the function:
function startTimer() {
        let timeValue = $('#clock').text();
        timeValue = timeValue.split(":");
        let minutes = parseInt(timeValue[0]);
        let seconds = parseInt(timeValue[1]);
        if (minutes > 0 || seconds > 0) {
            if (seconds == 00) {
                minutes--;
                seconds = 59;
            } else {
                seconds--;
            }
            $('#clock').text((minutes > 9 ? minutes : '0' + minutes) + ':' + (seconds > 9 ? seconds : '0' + seconds));
            pomodoroPercent();
        } else {
            $('#clock').text('00:00');
            pomodoroEnd();
            return;
        }
        setTimeout(startTimer, 1000);
    }
						
What is
pomodoroEnd?– Sergio
if Voce needs to run the function every 1 second, you can use the
setInterval()instead ofsetTimeout(). Just a detail, the way you did I believe there’s no way to interrupt– Neuber Oliveira
I tried to use setInterval(), but it gives some error and it doesn’t count right. In certain of 5 seconds it reaches 00:00 and restarts the count in infinite loop
– Weverton