title: Playlist with <audio> JavaScript
body: <p>I'm creating a personal small website and I want to play some songs on it. What I've tried to do is the following:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
  
  var i=1;
  var nextSong= &quot;&quot;;
  var audioPlayer = document.getElementById('audio');
  audioPlayer.onended = function(){
      i++
      nextSong = &quot;Music/&quot;+i+&quot;.mp3&quot;;
      audioPlayer.src = nextSong;
      audioPLayer.load();
      audioPlayer.play();
      if(i == 37) // this is the end of the songs.
      {
          i = 1;
      }
      
  }
  &lt;/script&gt;
  &lt;audio id=&quot;audio&quot;  src=&quot;Music/1.mp3&quot;controls=&quot;controls&quot; autoplay=&quot;autoplay&quot;   align=&quot;&quot;&gt; &lt;/audio&gt;
  </code></pre>
  <p>However, I can't get this to work. It just plays the first song and doesn't execute the JS. I've tried alerting the state of <code>i</code> for example but it doesn't do anything.</p>