title: Pomodoro Clock giving negative values
body: <p>Created a Pomodoro Clock using JavaScript. 
  It works fine, but once it gets to the break timer, and for everything after that, it gives me a negative time between seconds.</p>
  
  <p><a href="https://jsfiddle.net/3fehu668/" rel="nofollow">https://jsfiddle.net/3fehu668/</a></p>
  
  <p>JavaScript:</p>
  
  <pre><code>    $(document).ready(function(){
      var clock = $("#clock");
      var heading = $("h1");
      var breakMinus = $("#break-minus");
      var breakPlus = $("#break-plus");
      var sessionMinus = $("#session-minus");
      var sessionPlus = $("#session-plus");
      var breakTime = $("#break-time");
      var sessionTime = $("#session-time");
      var startButton = $("#start-btn");
      var resetButton = $("#reset-btn");
      var breakVal = parseInt(breakTime.val());
      var sessionVal = parseInt(sessionTime.val());
  
      breakMinus.on("click", function(){
          if (breakVal &gt; 0) {
              breakVal--;
              breakTime.val(breakVal);
          }
      });
  
      breakPlus.on("click", function(){
          breakVal++;
          breakTime.val(breakVal);
      });
  
      sessionMinus.on("click", function(){
          if (sessionVal &gt; 0) {
              sessionVal--;
              sessionTime.val(sessionVal);
          }
      });
  
      sessionPlus.on("click", function(){
          sessionVal++;
          sessionTime.val(sessionVal);
      });
  
      startButton.on("click", function(){
          if (valuesEntered()) {
              var finalTime = sessionVal * 60 + getTimeInSeconds();
              heading.html("Session running!");
              setInterval(function(){startTime(getTimeInSeconds(), finalTime)}, 1000);
          }
      });
  
      breakTime.on("input", function(){
          breakVal = parseInt(breakTime.val());
      });
  
      sessionTime.on("input", function(){
          sessionVal = parseInt(sessionTime.val());
      });
  
      function valuesEntered(){
          console.log("breakVal = " + breakVal);
          console.log("sessionVal = " + sessionVal);
          if (breakVal &lt; 0 || sessionVal &lt; 0) {
              alert("Time can't be negative! Check your inputs!");
          } else if (breakVal === 0 || sessionVal === 0){
              alert("Please enter a time for your break and session! (Time can't be 0)");
          } else {
              return true;
          }
      }
  
      function startTime(currentTime, finalTime){
          console.log("Setting timer...");
          setTime(currentTime, finalTime);
          if(finalTime === getTimeInSeconds()){
              alert("Time for a break!");
              heading.html("Break!");
              finalTime = breakVal * 60 + currentTime;
              clearTimer();
              setInterval(function(){startBreak(getTimeInSeconds(), finalTime)}, 1000);
          }
      }
  
      function clearTimer() {
          var intervalID = window.setInterval("", 9999); // get reference to last interval + 1
          clearInterval(intervalID - 1);
      }
  
      function startBreak(currentTime, finalTime){
          console.log("Break time...");
          setTime(currentTime, finalTime);
          if(finalTime === getTimeInSeconds()){
              alert("Back to work!");
              heading.html("Session running!");
              finalTime = sessionVal * 60 + currentTime;
              clearTimer();
              setInterval(function(){startTime(getTimeInSeconds(), finalTime)}, 1000);
          }
  
      }
  
      function setTime(currentTime, finalTime){
          console.log("Setting the time. Current Time = " + getTimeInSeconds() + ",  FinalTime = " + finalTime);
          var minutes = Math.floor((finalTime - currentTime) / 60);
          var seconds = (finalTime - currentTime) % 60;
          if (minutes &lt; 10) {
              minutes = "0" + minutes;
          }
          if (seconds &lt; 10) {
              seconds = "0" + seconds;
          }
          clock.html(minutes  + ":" + seconds);
      }
  
      function getTimeInSeconds() {
          var date = new Date();
          return date.getMinutes() * 60 + date.getSeconds();
      }
  });
  </code></pre>
  
  <p>I'm not posting the HTML and CSS code because I don't think its relevant. You can find it in the jsfiddle though.</p>