title: Vary SetInterval time
body: <p>I'm trying to vary the time of the setInterval function, by selecting a different value of an array. </p>
  
  <p>Why does the console log output return one index repeated, or nothing at all?</p>
  
  <pre><code>$("input.btn1").click(function() {
      var i = 0;
      //var timeOut = 1000;
  
      var timer = setInterval(function() {
  
  /*  
      var timeArr = [
          1000,2000,3000
      ];
      var randInt = getRandomInt(0, 2);
      var timeOut = timeArr[randInt]; 
  */      
  
  
      if( i &lt; btn2.length) {
               console.log("current timeout: " +timeOut);
           } else {
               clearInterval(timer);
              }
              i = i + 1;
          }, randTimeout());
  
  }); 
  
  
  function randTimeout() {
      var timeArr = [
          1000,2000,3000
      ];
      var randInt = getRandomInt(0, 2);
      var timeOut = timeArr[randInt]; 
  
      return timeOut;
  }
  
  function getRandomInt(min, max) {
      return Math.floor(Math.random() * (max - min + 1)) + min;
  }
  </code></pre>