Skip to content

Commit 0316d66

Browse files
implemented the function setAlarm
1 parent d281f82 commit 0316d66

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,25 @@ function formatTime(seconds){
88

99
}
1010
function setAlarm() {
11-
11+
// clearing any previous countdown
12+
if (intervalId !== null){
13+
clearInterval(intervalId)
14+
}
15+
const input = document.getElementById("alarmSet");
16+
totalSeconds = Number(input.value);
17+
18+
document.getElementById("timeRemaining").textContent = `Time Remaining: ${formatTime(totalSeconds)}`;
19+
20+
intervalId = setInterval(() => {
21+
totalSeconds--;
22+
document.getElementById("timeRemaining").textContent = `Time Remaining: ${formatTime(totalSeconds)}`;
23+
24+
if (totalSeconds <= 0) {
25+
clearInterval(intervalId);
26+
intervalId = null;
27+
playAlarm();
28+
}
29+
}, 1000);
1230

1331
}
1432

0 commit comments

Comments
 (0)