title: Pause and play Jquery timer using setInterval
body: <p>I have a timer running using jquery setInterval and a button that toggles between play and pause. I need the timer to pause and/or continue running when the user clicks on the play/pause button. Also, for some reason, the seconds goes from "59" to "01". It's skipping "00". I'm not sure why. Thanks for your help!</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;div id="clock"&gt;0:00&lt;/div&gt;
  
  &lt;div id="audioBtn"&gt;
     &lt;div class="btn play"&gt;&lt;/div&gt;
     &lt;div class="btn pause"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JQuery</strong></p>
  
  <pre><code>var output = $('#clock');
  var isPaused = false;
  var min = 0;
  var sec = 0;
  var t = window.setInterval(function() {
      if(!isPaused) {
          sec++;
          if (sec &lt; 10) {
              output.html(min + ":0" + sec);
          } else {
              output.html(min + ":" + sec);
          }
          if (sec === 59) {
              sec = 0;
              min++;
          }
      }
  }, 1000);
  
  if ($('.btn').hasClass('pause')) {
      $('#audioBtn').on('click', function(e) {
          e.preventDefault();
          console.log("should pause");
          isPaused = true;
      });
  };
  
  if ($('.btn').hasClass('play')) {
      $('#audioBtn').on('click', function(e) {
          e.preventDefault();
          console.log("should play");
          isPaused = false;
      });
  };
  </code></pre>