title: How to stop a time function nested in a function?
body: <p>I was able to get the following code from some class work I'm working on. It works really well for what I need it for and I like that I can call <code>startTime();</code> to start it. However, I'm now at a point where I need to figure out how to stop it.  Is there a way to do <code>startTime(stop);</code> or something similar? </p>
  
  <pre><code>function startTime() {
      let hours = 0;
      let minutes = 0;
      let seconds = 0;
      const timer = setInterval(function () {
          seconds++;
          if (seconds === 60) {
              minutes++;
              seconds = 0;
          }
          second.innerHTML = formatTime();
      }, 1000);
      function formatTime() {
          let sec = seconds &gt; 9 ? String(seconds) : '0' + String(seconds);
          let min = seconds &gt; 9 ? String(minutes) : '0' + String(minutes);
          return min + ':' + sec;
      }
  }
  </code></pre>