Pomodoro Clock Help with timer loop

I seem to be doing something wrong with the timer in my pomodoro clock. If I do
t = setInterval(countdown, 1000); The timer doesn’t loop
but if I do
t = setInterval(countdown(), 1000); My timer loops so fast that it goes straight to zero as opposed to changing every second.

What am I doing wrong?

Thanks in advance.

When the Start button is clicked, you call countdown and then inside countdown you set t = setInterval(countdown,1000). Why are you having the function call itself? You should move the following:

t = setInterval(countdown,1000);

to be inside the click event handler callback function for the button with id=“start-pause”. When you wrote countdown() as the callback function for setInterval, it was calling itself in a loop so timer was decremented by 1 as fast as it the function could call itself.

When you only put countdown for the callback function of the setinterval (which is how you should do it), the reason it was only running one time, is because your code set startPause = false and then after several lines later you have the following:

    //Pause the timer
    if (!startPause) {
      startPause = true;

Since startPause is false at this point, your code executes cdpause which stops the interval.

Thank You!!!

I got it to work

Does negative session time have any meaning?


 sessionTime = Math.max(1, sessionTime - 1)