0

could someone please help me to understand why my audio won't play?

html:

<div id = "One" class = "square" onmousedown = "playSound(1)" ></div>
<audio id = "sound1" src = "https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"/>

JS:

function playSound(val) {
var soundToPlay = document.getElementByID("sound"+val);
soundToPlay.play();
}

Much appreciated :)

Mouse
  • 173
  • 1
  • 1
  • 8
  • What happens when you place an alert at the top of your js function? Does it get triggered when you click the div? – Chris Jun 08 '16 at 13:17
  • Also, you are not reading the source properly. Try this: document.getElementByID("sound"+val).src; – Chris Jun 08 '16 at 13:19
  • Did you check this answer http://stackoverflow.com/a/9419328/4879022 ? – Techie Jun 08 '16 at 13:48

1 Answers1

0

You have a typo with a uppercase D in Id here:

getElementByID
//-this -----^

change to this:

function playSound(val) {
    var soundToPlay = document.getElementById("sound"+val); // lowerCase "d" required
    soundToPlay.play();
}
Jai
  • 74,255
  • 12
  • 74
  • 103