jeudi 1 décembre 2016

Javascript play mp3 from random number

I deleted my previous question as it wasn't clear enough.

Here's what I'm after: On page load - play an mp3 chosen after running a script for a random number (not list) and adding the ".mp3" to it...

This is what I got so far and it's not working:

<script type="text/javascript">
        
function myFunction() {
    var x = Math.floor((Math.random() * 6) + 1);
  }   
    
document.write ('<audio src= "media/' + x + '.mp3" controls autoplay></audio>')

</script>

Please help. thanks.




Aucun commentaire:

Enregistrer un commentaire