File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed
Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -2,16 +2,16 @@ let timerId = null;
22let remainingSeconds = 0 ;
33
44function updateDisplay ( ) {
5- let minutes = String ( Math . floor ( remainingSeconds / 60 ) ) . padStart ( 2 , "0" ) ;
6- let seconds = String ( remainingSeconds % 60 ) . padStart ( 2 , "0" ) ;
5+ const minutes = String ( Math . floor ( remainingSeconds / 60 ) ) . padStart ( 2 , "0" ) ;
6+ const seconds = String ( remainingSeconds % 60 ) . padStart ( 2 , "0" ) ;
77 document . getElementById (
88 "timeRemaining"
99 ) . textContent = `Time Remaining: ${ minutes } :${ seconds } ` ;
1010}
1111
1212function startCountdown ( ) {
13- if ( remainingSeconds < 0 ) remainingSeconds = 0 ;
1413 timerId = setInterval ( ( ) => {
14+ remainingSeconds -- ;
1515 updateDisplay ( ) ;
1616
1717 if ( remainingSeconds <= 0 ) {
@@ -20,20 +20,24 @@ function startCountdown() {
2020 timerId = null ;
2121 playAlarm ( ) ;
2222 }
23- remainingSeconds -= 1 ;
2423 } , 1000 ) ;
2524}
2625
2726function setAlarm ( ) {
2827 const input = document . getElementById ( "alarmSet" ) ;
2928 if ( input . value === "" ) return ;
30- const inputValue = Number ( input . value ) ;
29+ remainingSeconds = Number ( input . value ) ;
3130 clearInterval ( timerId ) ;
3231 timerId = null ;
33- remainingSeconds = inputValue ;
3432
35- updateDisplay ( ) ;
36- startCountdown ( ) ;
33+ if ( remainingSeconds <= 0 ) {
34+ remainingSeconds = 0 ;
35+ updateDisplay ( ) ;
36+ playAlarm ( ) ;
37+ } else {
38+ updateDisplay ( ) ;
39+ startCountdown ( ) ;
40+ }
3741 input . value = "" ;
3842}
3943
You can’t perform that action at this time.
0 commit comments