i am trying to play audio file on click of div, and then with the next click of the div pause it. However, I am very new to javascript and the first function isn't even executing, and i don't understand how it isn't defined.
here is my code:
<!DOCTYPE html>
<html>
<head>
<style>
.floating-box {
display: inline-block;
width: 150px;
height: 75px;
margin: 10px;
border: 3px solid #73AD21;
}
.after-box {
clear: left;
border: 3px solid red;
}
.player
</style>
</head>
<script>
var has_been_played = 0;
function playSound() {
var aud=new Audio(file);
aud.play();
var b1 = document.getElementbyId("box" + num);
var b1.has_been_played == true;
}
var b1.has_been_played = pauseAud() {
document.getElementById("box" + num).setAttribute("onClick",
"javascript: pauseAud();");
}
function pauseAud() {
var aud=new Audio(file);
aud.pause();
}
</script>
<body>
<div id="box1" class="floating-box" onclick="playSound('donttalk.mp3');"></div>
<div id="box2" class="floating-box" onclick="playSound('goodvibrations.mp3');"></div>
</body>
</html>
I want it to play the sound, and then once it has been clicked the variable changes to "has_been_played" and the next time you click that div the audio file will pause. (hopefully then, the next you click it it will play again.
Why is it saying that the function playSound is not defined onclick?