Skip to content

Commit 948b321

Browse files
committed
Refactor setAlarm function to validate input earlier in the process
1 parent 21079b1 commit 948b321

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ function setAlarm() {
99
return;
1010
}
1111

12+
let timeInSeconds = Number(inputElement.value);
13+
14+
if (isNaN(timeInSeconds) || timeInSeconds < 0) {
15+
alert("Please enter a valid number of seconds.");
16+
return;
17+
}
18+
1219
if (timerInterval) {
1320
clearInterval(timerInterval);
1421
}
1522
if (flashInterval) {
1623
clearInterval(flashInterval);
1724
}
1825

19-
let timeInSeconds = Number(inputElement.value);
20-
2126
function updateScreen(secondsRemaining) {
2227
const minutes = Math.floor(secondsRemaining / 60);
2328

0 commit comments

Comments
 (0)