Skip to content

Commit ea108ca

Browse files
authored
Implement alarm countdown display functionality
Added displayTime function to show remaining time and updated setAlarm to utilize it.
1 parent c75d3d0 commit ea108ca

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
1-
function setAlarm() {}
1+
function displayTime(time) {
2+
const remainingElement = document.getElementById("timeRemaining");
3+
4+
const minutes = String(Math.floor(time / 60)).padStart(2, "0");
5+
const seconds = String(time % 60).padStart(2, "0");
6+
7+
remainingElement.innerText = `Time Remaining: ${minutes}:${seconds}`;
8+
}
9+
10+
function setAlarm() {
11+
let time = parseInt(document.getElementById("alarmSet").value);
12+
displayTime(time);
13+
14+
const interval = setInterval(() => {
15+
time--;
16+
displayTime(time);
17+
if (time === 0) {
18+
clearInterval(interval);
19+
playAlarm();
20+
}
21+
}, 1000);
22+
}
23+
24+
25+
26+
27+
228

329
// DO NOT EDIT BELOW HERE
430

0 commit comments

Comments
 (0)