Skip to content

Commit 76f1971

Browse files
committed
alarm starts immediately
1 parent e618de2 commit 76f1971

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,19 @@ if (isNaN(parsed) || parsed < 0) {
5454
pauseAlarm(); // stop any playing audio
5555
audio.currentTime = 0;
5656

57-
// Start countdown every 1000ms
58-
timer = setInterval(() => {
59-
if (timeLeft > 0) {
60-
timeLeft--;
61-
updateDisplay(timeLeft);
62-
}
63-
64-
if (timeLeft === 0) {
65-
clearInterval(timer);
66-
startAlarm();
67-
}
68-
}, 1000);
57+
function tick() {
58+
if (timeLeft > 0) {
59+
timeLeft--;
60+
updateDisplay(timeLeft);
61+
} else {
62+
clearInterval(timer);
63+
startAlarm();
64+
}
65+
}
66+
67+
// Run once immediately for consistency
68+
tick();
69+
timer = setInterval(tick, 1000);
6970
}
7071

7172
function updateDisplay(seconds) {

0 commit comments

Comments
 (0)