title: JS - my loop using setTimeout stops looping
body: <p>I have the following code :</p>
  
  <pre><code>var i = 0, count = 10, randomId;
  
      function f(myArray) {
  
            // this will get a random value from myArray
          randomId = myArray[Math.floor( Math.random()*myArray.length )]; 
  
            // displays the random value
          alert (randomId);
  
  
          i++;
          if( i &lt; count ){
              setTimeout( f, 3000 );
          }
      }
  
      f(myArray);
  </code></pre>
  
  <p>The above code works but gives only one alert and then it stops.</p>
  
  <p>However it works properly (10 loops) with basic alerts such as <code>alert("hi")</code>, and remove the randomId line.</p>
  
  <p>It's as if anything complex within this function will block the loop, it will only handle basic alerts..</p>
  
  <p>Any help is appreciated, thanks :)</p>