title: Loop is not working properly
body: <p>I have create a javascript to change the audio after the audio ended.</p>
  
  <pre><code>var songlist = new Array("a.mp3", "b.mp3", "c.mp3", "d.mp3", "e.mp3", "f.mp3");
  var dir = "music/";
  var curr_track = 0;
  var isfirstrun;
  
  function start()
  {
      if(curr_track == songlist.length)
          curr_track = 0;
      var track = document.getElementById('track');
      track.innerHTML = curr_track;
      var audio = document.getElementById('audio');
      isfirstrun = true;
      audio.src = dir+songlist[curr_track];
      audio.load();
      audio.play();
      if(isfirstrun == true)
      {
          audio.addEventListener('ended', function(){ curr_track++; start();}, false); 
          isfirstrun = false;
      }
  }
  </code></pre>
  
  <p>And inside the HTML, </p>
  
  <pre><code>&lt;body onload="start();"&gt;
  </code></pre>
  
  <p>The <code>track</code> used in the code is to show what is the current track number, and I found out that the output is</p>
  
  <pre><code>0    then    1    then     3     then    7
  </code></pre>
  
  <p>Hence, it is missing <code>c.mp3</code>, <code>e.mp3</code> and <code>f.mp3</code> from the <code>songlist</code>.</p>
  
  <p>How can I solve the problem of the looping?</p>