Skip to content

Commit 83993fd

Browse files
committed
Implement alarm clock countdown logic
1 parent d0554ad commit 83993fd

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
function setAlarm() {}
1+
function setAlarm() {
2+
const timeInput = document.getElementById("alarmSet");
3+
let remainingTime = Number(timeInput.value);
4+
const timeRemainingDisplay = document.getElementById("timeRemaining");
5+
6+
timeRemainingDisplay.innerText = `Time Remaining: ${formatTime(remainingTime)}`;
7+
const countdownInterval = setInterval(() => {
8+
remainingTime -= 1;
9+
if (remainingTime === 0) {
10+
playAlarm();
11+
clearInterval(countdownInterval);
12+
}
13+
timeRemainingDisplay.innerText = `Time Remaining: ${formatTime(remainingTime)}`;
14+
}, 1000);
15+
}
16+
function formatTime(seconds) {
17+
const mm = String(Math.floor(seconds / 60)).padStart(2, "0");
18+
const ss = String(seconds % 60).padStart(2, "0");
19+
return `${mm}:${ss}`;
20+
}
221

322
// DO NOT EDIT BELOW HERE
423

0 commit comments

Comments
 (0)