Skip to content

Commit 383b8bf

Browse files
one second delay fixed
1 parent 33c4e01 commit 383b8bf

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,32 @@ function setAlarm() {
1818

1919
if (totalSeconds > 36000) {
2020
alert("Please enter a time less than 10 hours.");
21+
alarmInput.value = "";
2122
updateTime(0);
2223
return;
2324
}
24-
if (alarmInput.value === "" || totalSeconds < 0 || !Number.isInteger(0)) {
25-
alert("Please enter a valid positive time.");
25+
if (
26+
alarmInput.value === "" ||
27+
totalSeconds <= 0 ||
28+
!Number.isInteger(totalSeconds)
29+
) {
30+
alert("Please enter a valid number of seconds");
2631
updateTime(0);
32+
alarmInput.value = "";
2733
return;
2834
}
2935
alarmInput.value = "";
36+
3037
updateTime(totalSeconds);
3138

3239
timer = setInterval(() => {
33-
if (totalSeconds <= 0) {
34-
clearInterval(timer);
40+
totalSeconds--;
41+
updateTime(totalSeconds);
42+
43+
if (totalSeconds === 0) {
3544
playAlarm();
45+
clearInterval(timer);
3646
}
37-
updateTime(totalSeconds--);
3847
}, 1000);
3948
}
4049

0 commit comments

Comments
 (0)