Skip to content

Commit b7dcfeb

Browse files
committed
complete set alarm
1 parent 3a0b51d commit b7dcfeb

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

Sprint-3/alarmclock/alarmclock.js

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

333
// DO NOT EDIT BELOW HERE
434

0 commit comments

Comments
 (0)