Skip to content

Commit 6b24f06

Browse files
Alarm clock: decrement and update heading each second
1 parent 7cafbef commit 6b24f06

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ function setAlarm() {
1414
const input = document.getElementById("alarmSet");
1515
const heading = document.getElementById("timeRemaining");
1616

17-
const totalSeconds = Number(input.value);
18-
heading.innerText = `Time Remaining: ${formatTime(totalSeconds)}`;
17+
let remainingSeconds = Number(input.value);
18+
19+
heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;
1920

2021
if (intervalId !== null) {
2122
clearInterval(intervalId);
2223
}
23-
24+
2425
intervalId = setInterval(() => {
26+
remainingSeconds -= 1;
27+
28+
heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;
2529
}, 1000);
2630
}
2731

0 commit comments

Comments
 (0)