File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments