Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading