First, I shall start off by saying I am the worst coder you will ever meet. I'm trying to make a Javascript that allows me to press a single button and have a random sound play. My idea was to do a math random and to have a number correspond with a sound that would then do an if statement that would play. I really have no idea where to go from here. I actually have no idea if I'm even doing this right.
My Javascript
function myFunction() {
var x = Math.floor((Math.random() * 10) + 1);
var sounds = ["sound1", "sound2", "sound3", "sound4", "sound5", "sound6", "sound7", "sound8", "sound9", "sound10"];
sound1 = 1;
sound2 = 2;
sound3 = 3;
sound4 = 4;
sound5 = 5;
sound6 = 6;
sound7 = 7;
sound8 = 8;
sound9 = 9;
sound10 = 10;
sound1.src = "sound1.mp3";
//And so on of the sound files
}
My HTML
<button onclick="mySounds()">Click for a sound</button>
<p id="Sounds"></p>