Skip to content

Commit 6b7e254

Browse files
author
Pretty Taruvinga
committed
Restore alarm functionality by fixing input handling, variable naming, and timer logic"
1 parent 6cb11f7 commit 6b7e254

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function setAlarm() {
1818
timeLeft = parseInt(input, 10);
1919

2020
if (isNaN(timeLeft) || timeLeft <= 0) {
21-
alert("Please enter a valid number of seconds.");
2221
return;
2322
}
2423

@@ -29,13 +28,14 @@ function setAlarm() {
2928
updateDisplay(timeLeft);
3029

3130
timer = setInterval(() => {
32-
if (timeLeft > 0) {
33-
timeLeft--;
34-
updateDisplay(timeLeft);
35-
} else {
31+
if (timeLeft <= 0) {
3632
clearInterval(timer);
3733
playAlarm();
34+
return;
3835
}
36+
37+
timeLeft--;
38+
updateDisplay(timeLeft);
3939
}, 1000);
4040
}
4141

0 commit comments

Comments
 (0)