Skip to content

Commit 8f1a667

Browse files
committed
fix: reset timer identifier after alarm completes
1 parent 7342082 commit 8f1a667

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const titleElement = document.getElementById("timeRemaining");
2+
13
const ONE_SECOND_IN_MILLISECONDS = 1000;
24

35
let timeRemainingInSeconds = 0;
@@ -20,15 +22,14 @@ function formatTime(totalSeconds) {
2022
* Updates the display and checks if the alarm should sound.
2123
*/
2224
function updateTime() {
23-
const titleElement = document.getElementById("timeRemaining");
24-
2525
timeRemainingInSeconds = timeRemainingInSeconds - 1;
2626
titleElement.innerText = formatTime(timeRemainingInSeconds);
2727

2828
if (timeRemainingInSeconds === 0) {
2929
playAlarm();
3030
document.body.classList.add("flash");
3131
clearInterval(alarmTimerIdentifier);
32+
alarmTimerIdentifier = null; // ← reset to null for proper state management
3233
}
3334
}
3435

@@ -58,7 +59,6 @@ function setAlarm() {
5859
audio.play();
5960
audio.pause();
6061

61-
const titleElement = document.getElementById("timeRemaining");
6262
titleElement.innerText = formatTime(timeRemainingInSeconds);
6363

6464
alarmTimerIdentifier = setInterval(() => {

0 commit comments

Comments
 (0)