Stuck with pomodoro clock, help please!

Hey everyone,
so Im making my pomodoro clock and I’m basically stuck at this point:

I don’t know how to make the function run over and over again, I don’t know how to get it to “pause” and pick up at the value it was stopped… not to mention there are like 5 tests that I think I should be passing and I’m not.
Can anyone offer some guidance as to where to look?
As I mentioned I’m pretty stuck. Been going back and forth with a couple variations of the same thing for the last few hours and I’m starting to feel really frustrated.

thanks in advance!!

setInterval() repeatedly calls a function on every given interval.
You can pause it by removing registered setInterval().
You can save the time just before the removal of setInterval()

Alternatively, you can use requestAnimationFrame() or setTimeout(), but be sure to do your own research about them.

1 Like

Which tests are those?

In Timer, 1 and 9 basically. 12 and 13 I guess it’s because it’s not running over and over which is one of my main problems right now. I’ve tried calling the function from within itself but it doesn’t work.

Hey everyone,

I’m stuck with my pomodoro clock.
In short I’m having problems:
1 - getting the timer to run over and over again
2 - getting the timer label to update to session/break depending on what’s happening
3 - getting the function to stop when the button is clicked and start again from that saved time

I know my code is probably terrible but I’ve hit a wall . I’ve tried other things but nothing seems to work. I don’t want to use jQuery and I’d like to do it in vanilla JS because I need to get passed this in order to improve. But I’d appreciate some guidance because I’m pretty much stuck.

Here’s my pen:

Thanks in advance!

I don’t see any variable that would indicate that the game is started or stopped. This variable would be needed to function as a condition for when a change in display should be made. If this variable indicate that the game is paused, then you could calculate how much time has passed while the timer was stopped and add the time to the then variable in your timer function and continue to calculate the time left by deducting from the new then the, thus making sure that when the game is restarted the timer continues from the right time.

Also, in your reset function at line 93 you clear a timeout called countdown even if no such setTimeout was introduced (you have a setInterval).

1 Like

First of all, thanks so much for your help! I appreciate it a lot.
Ok, I fixed the reset function. It was just a mistake due to frustration lol.
Now onto the other part:
I added an isPaused variable and it works properly. I’m only having trouble setting the timer to the timeElapsed variable where I’m holding the secondsLeft before the interval is cleared. And I still can’t figure out how to get the function to run over and over again, and updating the label (which seems so simple but it’s driving me crazy).
I tried refactoring the whole thing and it doesn’t get as close as this one, so I think I’ll just stick to debugging this one, even though the other one looks neater.
Why isn’t the timer starting from the value I’m setting it to?
Thanks again!!

Something I find strange: you seem to take variables from innerHTML (see line 80). Why? You use the interface to change variables and then transfer to html and then retrieve them from there. Why do that and not use sessionTime and breakTime directly? This seems rather inefficient as DOM calls are resource intensive.

In the onclick for the Start/Pause button you call startTimer(), which is defined as function startTimer(minutes). You can guess what value minutes gets when this button is clicked.