diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..2a4aca918 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,29 @@ -function setAlarm() {} +let alarmTimer; + +function setAlarm() { + clearTimeout(alarmTimer); + + let secondsRemaining = Number(document.getElementById("alarmSet").value); + + function updateTimer() { + const minutes = Math.floor(secondsRemaining / 60); + const seconds = secondsRemaining % 60; + + document.getElementById("timeRemaining").innerText = + `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; + + if (secondsRemaining === 0) { + playAlarm(); + return; + } + + secondsRemaining--; + + alarmTimer = setTimeout(updateTimer, 1000); + } + + updateTimer(); +} // DO NOT EDIT BELOW HERE @@ -22,4 +47,4 @@ function pauseAlarm() { audio.pause(); } -window.onload = setup; +window.onload = setup; \ No newline at end of file diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..4a91379d3 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ -