Im trying to create a simple countdown timer that plays a beep when it's done. My countdown timer is working. My sound file has been created and is in place. The script to play the sound file is not working, and thats what Im asking for help with.
Ive looked around for answers, and most recommend hooking up to an external JS library, which I do not want to do. That being said, here is my code:
<script language="Javascript">
var countdown;
var countdown_number;
var audio = new Audio('audio/beep.mp3');
function countdown_init() {
countdown_number = 11;
countdown_trigger();
}
function countdown_trigger() {
if(countdown_number > 0) {
countdown_number--;
document.getElementById('countdown_text').innerHTML = countdown_number;
if(countdown_number > 0) {
countdown = setTimeout('countdown_trigger()', 1000);
if(countdown_number === 0) { audio.play(); }
}
}
}
function countdown_clear() {
clearTimeout(countdown);
}
</script>
<div>
<input type="button" value="start countdown" onClick="countdown_init()" />
<input type="button" value="stop countdown" onClick="countdown_clear()" /> <br /><br />
</div>
<div id="countdown_text">Placeholding text</div>