Uncaught TypeError: Cannot read property 'style' of null naptime.js:8
5Uncaught ReferenceError: value is not defined
I am designing a simple count down timer that plays music.
I cannot figure out what the errors are. Can anyone shed some light on the problem. Thank you.
here are the two files.
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Programming a Timer with HTML5 Audio</title> </head> <script LANGUAGE="Javascript" src= "naptime.js"></script> <body > <p id="wakeup">WAKE UP</p> <form name="napTime" onsubmit="0" id="dashboard"> <input type="text" id="seconds" name="seconds" size="5" value="60" /> <input type="button" value="Start Nap" id="start" /> <input type="button" value="Pause Music" id="toggle" /> </form> <audio id="audiotag1" src="http://www.santarosa.edu/~jperetz/fall2012/projects/naptime/stellar.mp3" preload="auto"></audio> <script src= "naptime.js"></script> </body> </html>
naptime.js
// javascript document. naptime .js
var timer = new Date();
var seconds = document.getElementById('seconds');
var dashboard = document.getElementById('dashboard');
var wakeup = document.getElementById('wakeup');
wakeup.style.display = "none";
function alarm() {
timer.setSeconds(timer.getSeconds() - 1);
seconds.value = timer.getSeconds();
if (timer.getSeconds() === 0) {
wakeup.style.display = "block";
dashboard.style.display = "none";
}
}
var start = document.getElementById('start');
start.addEventListener('click', takeNap);
var audioElement = document.getElementById('audiotag1');
function takeNap() {
timer.setSeconds(seconds,value);
window.setInterval(alarm,1000);
start.style.display ="none";
onOff.style.display = "inline";
playMusic();
}
var onOff = document.getElementById("toggle");
onOff.style.display = "none";
onOff.addEventListener('click', pausePlay);
audioElement.addEventListener('ended', playMusic);
function playMusic() {
audioElement.play();
}
function pausePlay() {
if (onOff.getAttribute("value") === "Pause Music") {
audioElement.pause();
onOff.setAttribute("value", "Resume Music");
} else {
audioElement.play();
onOff.setAttribute("value", "Pause Music");
}
}

New Topic/Question
Reply



MultiQuote




|