diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..488c199db 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,30 @@ -function setAlarm() {} +function setAlarm() { + let timeRemaining = document.getElementById("alarmSet").value; + const timeDisplay = document.getElementById("timeRemaining"); + + // Create a reusable function to update the text on the screen + const updateDisplay = (time) => { + let minutes = Math.floor(time / 60) + .toString() + .padStart(2, "0"); + let seconds = (time % 60).toString().padStart(2, "0"); + timeDisplay.innerText = "Time Remaining: " + minutes + ":" + seconds; + }; + + // STEP 1: Display the starting time IMMEDIATELY + updateDisplay(timeRemaining); + + // STEP 2: Start the interval + const countdown = setInterval(() => { + timeRemaining--; + updateDisplay(timeRemaining); + + if (timeRemaining <= 0) { + clearInterval(countdown); + playAlarm(); + } + }, 1000); +} // DO NOT EDIT BELOW HERE