Skip to content

Commit bf7dfb9

Browse files
committed
Fix alarm input validation and improve alert messages
1 parent 4ced47d commit bf7dfb9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@ let remainingSeconds = 0;
44
function setAlarm() {
55
let timeRemaining = document.getElementById("timeRemaining");
66
let alarmSet = document.getElementById("alarmSet").value;
7-
remainingSeconds = Number(alarmSet);
7+
8+
remainingSeconds = parseInt(alarmSet);
9+
810
if (isNaN(remainingSeconds) || remainingSeconds <= 0) {
9-
prompt("please enter a value greater than zero!");
11+
alert("please enter a value greater than zero!");
12+
return;
13+
}
14+
15+
if ((remainingSeconds > 86, 400)) {
16+
alert("Please enter a time less than 24 hourse (86,400)");
1017
return;
1118
}
1219
displayTime();
20+
21+
if (countDown) {
22+
clearInterval(countDown);
23+
}
1324
countDown = setInterval(timer, 1000);
1425
}
1526

0 commit comments

Comments
 (0)