diff --git a/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js b/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js index 6ca81cd..835d1ce 100644 --- a/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js +++ b/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js @@ -1,4 +1,36 @@ -function setAlarm() {} + + + +function setAlarm() { + //Access to the DOM + let timeRemaining = document.getElementById('timeRemaining'); + let alarmSet = document.getElementById('alarmSet'); + + let inputNumber = alarmSet.value; + let minutes = Math.floor(inputNumber/60); + let seconds = inputNumber % 60; + + let interval = setInterval(() => { + if (minutes > 0 && seconds === 0) { + minutes--; + seconds = 59; + } + + if (seconds === 0) { + clearInterval(interval); + audio.play(); + let bgClock = document.body.style.backgroundColor = "magenta"; + bgClock.reset(); + } + + timeRemaining.innerHTML = 'Time Remaining: ' + minutes + ':' + seconds; + seconds--; + }, 1000); + + audio.pause(); +} + + // DO NOT EDIT BELOW HERE diff --git a/Week-3/Homework/mandatory/1-alarmclock/index.html b/Week-3/Homework/mandatory/1-alarmclock/index.html index ab7d582..8a8ed13 100644 --- a/Week-3/Homework/mandatory/1-alarmclock/index.html +++ b/Week-3/Homework/mandatory/1-alarmclock/index.html @@ -17,7 +17,8 @@