title: get interval ID from else statement when set in IF
body: <p>I am attempting to create a responsive slider, that will change to a simple set of dot points when in mobile mode (<code>&lt; 940</code>).</p>
  
  <p>The issue I am facing is in my else statement I am unable to clearintervals that were made in the if statement, because t comes up as undefined. I have resorted to using</p>
  
  <p><code>for (var i = 1; i &lt; 99999; i++) window.clearInterval(i);</code> to clear the interval which works, but I don't like it because it's ugly and cumbersome, is there another way of accomplishing this?</p>
  
  <pre><code> $(document).ready(function() {
  
      function rePosition() {
  
          //get responsive width
          var container_width = $('.container').width();
  
          //Slider for desktops only
          if(container_width &gt;= 940) {
  
              //get variables
              var slide_width = $('.slider_container').width();
              var number_of_slides = $('.slider_container .slide').length;
              var slider_width = slide_width*number_of_slides;
  
              //set element dimensions
              $('.slide').width(slide_width);
              $('.slider').width(slider_width);
  
              var n = 1;
              var t = 0;
              $('.slider_container').hover(function() { 
                  clearInterval(t);
                  }, function() {
                  t = setInterval(sliderLoop,6000);
              });
  
              var marginSize = i = 1;
  
              //Called in Doc Load
              function sliderLoop(trans_speed) {
  
                  if (trans_speed) {
                      var trans_speed = trans_speed;
                  }
                  else
                  {
                      var trans_speed = 3000;
                  }
  
                  if (i &lt; number_of_slides) {
                      marginSize = -(slide_width * i++);
                  }
                  else
                  {
                      marginSize = i = 1;
                  }
  
                  $('.slider').animate({ marginLeft: marginSize }, trans_speed);  
              }
  
              t = setInterval(sliderLoop,6000);
  
              $('.items li').hover(function() {
                  $('.slider').stop();
                  clearInterval(t);
                  var item_numb = $(this).index();
                  i = item_numb;
                  sliderLoop(500);
              }, function() {
                  t = setInterval(sliderLoop,6000);
              });
  
          }
          else
          {
  
              for (var i = 1; i &lt; 99999; i++)
              window.clearInterval(i);
              $('.slider').stop(true, true);
              $('.slider').css('margin-left', '0px');
  
              //rearrange content
              if($('.slider .slide .slide_title').length &lt; 1) {
                  $('.items ul li').each(function() {
                      var item_numb = $(this).index();
                      var content = $(this).text();
                      $('.slider .slide:eq(' + item_numb + ')').prepend('&lt;div class="title slide_title"&gt;' + content + '&lt;/div&gt;')
                  });
              }
          }
  
      }
  
      rePosition();
  
      $(window).resize(function() {
        rePosition();
      });
  
  });
  </code></pre>