diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..aa0278534 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,7 +1,36 @@ -function setAlarm() {} +let timer = null; -// DO NOT EDIT BELOW HERE +function formatTime(totalSeconds) { + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; +} + +function updateDisplay(seconds) { + document.getElementById("timeRemaining").textContent = + `Time Remaining: ${formatTime(seconds)}`; +} + +function setAlarm() { + if (timer) { + clearInterval(timer); + } + let seconds = Number(document.getElementById("alarmSet").value); + updateDisplay(seconds); + + timer = setInterval(() => { + seconds--; + updateDisplay(seconds); + + if (seconds <= 0) { + clearInterval(timer); + playAlarm(); + } + }, 1000); +} + +// DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); function setup() { @@ -22,4 +51,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..2c403ab6e 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm Clock app