Skip to content

Commit 5d17875

Browse files
Updating the app as per the review comments
1 parent eb90347 commit 5d17875

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Sprint-3/alarmclock/alarmclock.js

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

17-
let remainingSeconds = Number(input.value);
17+
let value = input.value
18+
19+
if (value === "") {
20+
return;
21+
}
22+
23+
let remainingSeconds = Number(value);
24+
25+
if (remainingSeconds <= 0 || isNaN(remainingSeconds)) {
26+
return;
27+
}
1828

1929
heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;
2030

@@ -24,14 +34,15 @@ function setAlarm() {
2434

2535
intervalId = setInterval(() => {
2636
remainingSeconds -= 1;
27-
28-
heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;
29-
30-
if (remainingSeconds === 0) {
37+
38+
if (remainingSeconds <= 0) {
39+
heading.innerText = `Time Remaining: ${formatTime(0)}`;
3140
playAlarm();
3241
clearInterval(intervalId);
3342
intervalId = null;
43+
return;
3444
}
45+
heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;
3546
}, 1000);
3647
}
3748

0 commit comments

Comments
 (0)