Hey guys I’m working on my pomdoro clock with jQuery. I have almost finished but when my timer is paused and then played after the initial start it starts to count down two values in the seconds area.
This is my countDown function:
function countDown(m,s) {
runTime = setInterval(function() {
if(isStarted) {
if (m == 0 && s == 0) {
stopTimer();
if (loop == 0) {
timeLeft = break_interval_m;
loop += 1;
$('#timer-label').text('Break');
} else {
timeLeft = ses_interval_m;
loop -= 1;
$('#timer-label').text('Session');
}
alarm.play();
countDown(timeLeft,0);
} else if (s != 0) {
if (s <= 10){
s -= 1;
timeLeft = m + ':0' + s;
} else {
s -= 1;
timeLeft = m + ':' + s;
}
} else if (s == 0) {
s = 59;
m -= 1;
timeLeft = m + ':' + s;
}
$('#time-left').text(timeLeft);
}
}, 1000);
}
and this is my start_stop click function:
$('#start_stop').click(function() {
start_stop_counter++
if (Number.isInteger(start_stop_counter/2)){
isStarted = false;
pauseButton();
}
else {
isStarted = true;
playButton();
countDown(ses_interval_m, ses_interval_s)
}
})
The code seems to be decrementing two values at once. What am I missing?
Here is the full code