-3
I want to create a project to make a kind of game for me to study music. I would play a chord and I would reply what grade it would be. The system would give me the answer whether I got it right or not. This is to train my ear. So I’m starting with the first steps, but I can’t point to a file name in the array.
index.html
:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>
OUVIDO ABSOLUTO
</title>
<script src='/scripts/sons.js'></script>
</head>
<body>
<br><br>
<audio id="audio"></audio>
<form>
<label form="tocar">
<input type="button" value="tocar" onclick="tocar()">
</label>
</form>
</body>
</html>
scripts/sons.js
:
lista_acordes=["C.wav", "D.wav", "E.wav"];
function tocar() {
var son = document.getElementById("audio");
son.src=lista_acordes[1];
son.play();
}
I don’t think the question is duplicate, nor even appear. A question is about how to call an external file, and this is how to assign a value to an Html attribute by Javascript.
– LeAndrade
@Leandrade You’re right. I read both and they looked the same to me. I’ve reopened. ;)
– Sam
No problem @Sam :) the community is always to help, we go!
– LeAndrade
Andre seems to me that you missed just one src on the tag
audio
, because when you do it in Javascriptson.src=lista_acordes[1];
son which is the variable name for the audio tag does not have the src attribute yet.– LeAndrade