title: Javascript audio loop
body: <p>I want to play an audio in background 3 times and after 3 times the audio will stop automaticlly.
  I've tried this code and it did not work.
  HTML CODE:</p>
  
  <pre><code>&lt;audio id='beep' controls&gt;
  &lt;source src="beep-02.mp3" type="audio/mpeg"&gt;
  Your browser does not support the audio element.
  &lt;/audio&gt;
  </code></pre>
  
  <p>JAVASCRIPT:</p>
  
  <pre><code>var count = 1
  document.getElementById('beep').addEventListener('ended', function(){
     this.currentTime = 0;
     if(count &lt;= 3){
        this.play();
     }
     count++;
  }, false);
  </code></pre>
  
  <p>Thanks.</p>