title: How to call function in if statement - javascript
body: <p>I've got an interval set that I want to be cleared/end when someone hits a button called "Reset" this way the function to begin the interval is fresh and ready to accept new values.</p>
  
  <p>How can this be done?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;div class="grid"&gt;
    &lt;div id="circle" class="center"&gt;
      &lt;div id="timer" class="fl"&gt;&lt;/div&gt;
        &lt;div class="grid"&gt;
          &lt;div class="col-1-2 center"&gt;
            &lt;div class="circleSelect"&gt;
              &lt;select id="min" class="fm"&gt;  
                &lt;option value="0"&gt;0 minutes&lt;/option&gt;
                &lt;option value="300"&gt;5 minutes&lt;/option&gt;
                &lt;option value="600"&gt;10 minutes&lt;/option&gt;
                &lt;option value="900"&gt;15 minutes&lt;/option&gt;
                &lt;option value="1200"&gt;20 minutes&lt;/option&gt;
                &lt;option value="1500"&gt;25 minutes&lt;/option&gt;
              &lt;/select&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="grid"&gt;
    &lt;div class="col-1-3 center centerText prZ ptm"&gt;
  
      &lt;div id="begin"&gt;
      &lt;a class="btn fm" onClick="begin()"&gt;Begin Meditation&lt;/a&gt;
      &lt;/div&gt;
  
      &lt;div id="during" class="opacity"&gt;
      &lt;a class="btn fm black" onClick="stop()"&gt;Pause&lt;/a&gt;
      &lt;a class="btn fm red" onClick="resetTime()"&gt;Reset&lt;/a&gt;
      &lt;a class="btn fm red" onClick="finish()"&gt;Finish Test&lt;/a&gt;
      &lt;/div&gt;
  
      &lt;div id="finish" class="centerText ptm grid opacity"&gt;
        &lt;div id="quote" class="pbm col-1-2 center"&gt;
            &lt;p class="centerText fm"&gt;"Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment."
             &lt;p class="fm"&gt;- Buddha&lt;/p&gt;
            &lt;/p&gt;
          &lt;/div&gt;
          &lt;a id="again" class="btn fm" onClick="again()"&gt;Meditate Again&lt;/a&gt;
  
      &lt;/div&gt;
  
    &lt;/div&gt;
  
    &lt;audio id="soundName" style="display: none;"&gt;&lt;/audio&gt;
  &lt;/div&gt;
  &lt;script&gt;
  
    function begin() {
  
      var min = parseInt($('#min').val(), 10);
      var sec = 1;
      var time = min + sec; 
  
      setInterval( function() {
        if (time &gt; 0){
          --time;
        }
        else if(time == 0){
          time = -1;
          finish();
        }
      }, 1000);
  
      function convertTime() {
          var mins = Math.floor((min % 3600) / 60);
          var secs = (sec % 60);
          // return humanTime;
  
          if (mins &gt;= 0){
          var timeTravel = setInterval( function() {
            --secs;
  
          if (secs == -1 &amp;&amp; min &gt; 0){secs = 59; --mins;}  // changes the minute 
          else if (secs == 0 &amp;&amp; min == 0) {clearInterval(timeTravel);} // stops at 00:00
  
  
          var humanTime = (((mins &lt; 10) ? "0" : "") + mins + ":" + ((secs &lt; 10) ? "0" : "") + secs);
          $('#timer').html(humanTime).fadeIn(200);
          }, 1000); 
        } else {}
  
      }
  
      convertTime();
  
      $('#begin').fadeToggle(200);
      $('.selectStyle').fadeToggle(200);
      $('.circleSelect').fadeToggle(200);
      $('#during').delay(200).fadeToggle(400);
  
    }
  
    function stop() {
  
    }
  
  
    function resetTime(interval) {
      $('#during').fadeToggle(200);
      $('#begin').delay(200).fadeToggle(400);
      $('.selectStyle').fadeToggle(200);
  
      var interval = clearInterval(timeTravel);
  
      resetTime();
    }
  
  
    function finish() {
  
  
      $('#during').fadeOut(200);
      $('#circle').fadeOut(500);
  
      $('#finish').insertAfter('#circle').delay(1000).fadeToggle(400);
    }
  
    function again() {
      $('#finish').fadeOut(200);
      $('#begin').delay(200).fadeToggle(200);
      $('#circle').delay(200).fadeToggle(400);
      $('.selectStyle').fadeToggle(200);
  
    }
  
  
  &lt;/script&gt;
  </code></pre>