I want a script to change the background music randomly
this is the code I tried , but it doesn't work:
<!DOCTYPE html>
<html>
<body>
<script>
var BGM = [];
BGM[0] = "BGM/BGM1.mp3";
BGM[1] = "BGM/BGM2.mp3";
BGM[2] = "BGM/BGM3.mp3";
BGM[3] = "BGM/BGM4.mp3";
BGM[4] = "BGM/BGM5.mp3";
BGM[5] = "BGM/BGM5.mp6";
var idx = Math.round( Math.random() * 5 );
document.write("<embed src='"+BGM[idx]+"' autostart=true hidden=true loop=true'>);
</script>
</body>
</html>
What have I done wrong?