Pomodoro clock help (2)


I wish to refine my clock later, but I can only do that once I figure out how to fix an unintended bug I’ve been having. Upon hitting the reset button after break is over, times are set to 0:25 and 0:05 instead of 25 and 5. I’ve been moving variables around but nothing works. Any idea what’s going on?


You’re getting confused about what the variables count and breakCount represent. Are they minutes or seconds?

At the beginning of your program:

  var alarm = $("#alarm")[0];
  var count = parseInt($("#sessionNum").html());
  var breakCount = parseInt($("#breakNum").html());
  $("#start").click(function() {
    var counter=setInterval(timer,10);
    count *= 60;

You extract them as minutes from the html and then multiply them by 60 to get seconds. But then after your session, when you reset them, you reset them as if they are minutes. In lines 22-29 you have:

        count = 25;
      else {

So, you are resetting count to 25 minutes, but then immediately do math on it as if it were seconds. You do something similar with breakCount.

You need to decide which and stick with it. Personally, seconds makes the most sense to me. Just make sure that those variables never hold anything except seconds.

So line 22 should be:

        count = 25*60;

And instead of line 3:

  var count = parseInt($("#sessionNum").html());

and then line 9:

count *= 60;

Just make line 3:

  var count = parseInt($("#sessionNum").html()) * 60;

and get rid of line 9.

Just make count always seconds. You can display it however you want, but in the JS, count is always seconds. And do the same for breakCount. If there is any confusion, then I might call them countSeconds and breakCountSeconds. It makes it very clear and it’s a good reminder. That’s the kind of thing that can save your life if you have to come back in a few years and fix something in the code and you’re not sure what everything is.

But the short answer is line 22 and 42 - if you add *60 to those equations, then it works. But you should make those other changes too.


Silly of me to overlook this, thank you very much for the comprehensive reply!