title: How to update the variable value in setinterval function on button click
body: <p>I am running a timer in my application which stores the value of minutes and seconds in cookie. On certain time period the popup will prompt once if user click OK button in the popup the timer need to reset and again start initial value.</p>
  
  <pre><code>function startTimer(duration) {
              var timer = duration,
                  minutes, seconds;            
              var seesionIdState = 0;
              setInterval(function() {  
              minutes = parseInt(timer / 60, 10);
              seconds = parseInt(timer % 60, 10);              
                  if (seesionIdState == 0) {
                      minutes = minutes &lt; 10 ? "0" + minutes : minutes;
                      seconds = seconds &lt; 10 ? "0" + seconds : seconds;
                      var date = new Date();
                      date.setTime(date.getTime() + (minutes * 60 * 1000));
                      cookie.set("minutes", minutes.toString(), {});
                      cookie.set("seconds", seconds.toString(), {});
                      if (--timer &lt; 0) {
                          timer = 0;
                      }
                      if (minutes == 1 &amp;&amp; seconds == 00) {
                          if ($window.innerWidth &gt; 767) {
                              angular.element("#sessionId").modal({
                                  backdrop: 'static'
                              });
                              setTimerforPopup();
                          } else {
                              angular.element("#sessionIdMobile").modal({
                                  backdrop: 'static'
                              });
                              setTimerforPopup();
                          }
  
                      } else if (minutes == 00 &amp;&amp; seconds == 00) {
                          seesionIdState++;
                      }
  
                  } else {
                      var minutes_data = getCookie("minutes");
                      var seconds_data = getCookie("seconds");
                      if (!minutes_data || !seconds_data) {
                          return;
                      }
                      cookie.remove('minutes');
                      cookie.remove('seconds');
                  }
  
              }, 1000);
          }
  startTimer(60);
  </code></pre>
  
  <p>If OK button clicks I will again call the function <code>startTimer(60);</code>. But the problem I am facing is the <code>setinterval</code> variable <code>timer</code> is not get updated its is proceeding with the old value.</p>
  
  <p>Please help me out to reset and start from given value.</p>