Tell us what’s happening:
I passed 28/29 test cases but failed at 12. The timer reached 00:00 then I see a new countdown begin when the timer-label
changed to Beak. What’s wrong with my createInterval
function?
Your code so far
My codepen is here.
// global variables
const intervalMs = 1000;
let interval = null;
let isBreakTime = true;
// This is the function that creates the interval for the timer.
function createInterval() {
interval = setInterval(() => {
const currentTime = formatTimeToSeconds(
timeLeftElement.textContent
);
if (currentTime) {
const nextTime = currentTime - intervalMs / 1000;
timeLeftElement.textContent = formatSecondsToString(nextTime);
} else {
playAudio();
if (interval) clearInterval(interval);
createInterval();
if (isBreakTime) {
timerLabelElement.textContent = "Break";
isBreakTime = false;
runTimer(breakLengthElement.innerHTML);
} else {
timerLabelElement.textContent = "Session";
isBreakTime = true;
runTimer(sessionLengthElement.innerHTML);
}
}
}, intervalMs);
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
.
Challenge: Build a 25 + 5 Clock (Pomodoro timer)
Link to the challenge: