Need help with my pomodoro clock

Need help with my pomodoro clock
0

#1

I can make it count down, and the color changes to show which session is counting, but then I reach a few issues:
It won’t stop after 0
It won’t accept the pause button
It won’t accept the reset button.

I know it is only a simple thing I’m missing, but those details get me in trouble.

Your help is appreciated.

Here’s my codepen: https://codepen.io/KoniKodes/full/pEMmdr/


#2

Couple of tips to help get back on track.

When I look at the debug console I can see “Error: Bootstrap’s JavaScript requires jQuery”. To fix this you need to drag the bootstrap External JavaScript library below the jQuery libraries so jQuery loads first.

Relating to the pause button, you have to store the output of setInterval() in order to stop the interval.

You can see here: https://codepen.io/cjsheets/full/dpxBpY/ I added the variable timerID, added a return statement to startCtmnr, and cleared timerID when the pause button is pressed.

Regarding your other questions, the trick will be to store the time when you pause and use the stored time when the timer is restarted.


#3

Has this been resolved?


#4

Thank you so much! I knew I was missing something. The pause button does work now, and I have a better footing to move forward.

It makes sense to return to startCtmnr.

I think I found the answer to my first question, to make it stop after zero so I can change to the break timer.


#5

The pause button still doesn’t seem to work for me, and the timer starts adding negative numbers at the end of the time instead of stopping at zero.


#6

Thank you. I am still working to implement the suggestions from @cjsheets.

I have not been able to stop the negative numbers. It is supposed to change to playtime once it hits zero.

Do you have a suggestion on how to make that happen?


#7

You can stop the timer using the timerID variable when you call clearInterval()

    if (--ctmnr < 0) {
      clearInterval(timerID);
    }

I updated my copy here to show the timer stopping at 00:00.

You need to add logic or a function call after clearInterval(timerID) to control what happens next. Maybe write a function that detects if worktime or playtime just ended, resets the runtime and restarts the clock. If you have trouble with that logic let me know and I’d be happy to help further.


#8

Thank you. I made my mistake by calling the startCtmnr instead of the timerId,

I will send it the change function and check if it is on work or play :slight_smile:

Update:
I actually got the stop at zero to work. And it did change over to playtime - even played the music. But it would not change back to worktime. And now I get this message: Uncaught ReferenceError: startCtmnr is not defined(…) - which where the counter takes place…

I believe that I may be out of scope, but I can’t see it. Do you mind looking again, please?