Pomodoro Clock...Why Do Tests 13 and 15 Fail?

Hey there.

I could sure use some of your help. I’ve been stuck on passing the tests for the pomodoro clock front end project. I built a pomodoro timer using Vanilla JS. It appears to function and pass all the user stories when I test it manually, however there are two tests that I haven’t been able to figure out. Currently the last audio test, but I haven’t looked into it yet, so no need to provide feedback on that one.

Test 13: When a session countdown reaches zero (NOTE: timer MUST reach 00:00), a new break countdown should begin, counting down from the value currently displayed in the id=“break-length” element.

AssertionError: Timer has reached zero but didn’t switch to Break time: expected ‘session’ to not equal 'session’

Test 15: When a break countdown reaches zero (NOTE: timer MUST reach 00:00), a new session countdown should begin, counting down from the value currently displayed in the id=“session-length” element.

AssertionError: Timer has switched back to Session time, but it didn’t start with the correct value.: expected 0 to equal 25

I can’t figure out why the timer fails to switch between session/break, as I’ve not been able to replicate the problem. After doing lots of research on the project, I suspect that the timer either may be off by a few seconds for some reason, or the code calls too many timer functions. May you please take a look at my code, I’m grateful for any feedback you may have.

Here’s the codepen: Pomodoro Clock

Thank you!!

I managed to solve this issue. See the updated code here: Pomodoro Clock

Before, I used clearInterval() within the timer() function to stop the countdown and then recursively called the timer() function when the clock hit “00:00” to initiate a new break/session timer. I believe this created multiple countdowns.

So, I changed the scope of the variable assigned to setInterval() to global. This allowed me to call clearInterval() within the startStop() and reset() functions. I then refactored the timer() function to only control the clock’s countdown and just updated the new time after “00:00” hit. I let startStop() handle resuming the timer altogether.

I hope this helps anyone encountering similar issues.

1 Like