title: html5 play audio loop 4x then stop
body: <p>Hi I need to loop audio file a certain number of times ie 4, I have the sound file looping correctly, code below. ? how to stop loop after 4x, many thanks P</p>
  
  <pre><code>$('#play_audio').click(function () {
              var audio = document.createElement("audio");
              audio.src = "files/windows%20default.mp3";
  
              audio.addEventListener('ended', function () {
                  // Wait 500 milliseconds before next loop
  
                  setTimeout(function () { audio.play(); }, 500);
              }, false);           
  
              audio.play(); 
      });
  </code></pre>