File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -18,15 +18,15 @@ function updateDisplay() {
1818 const heading = document . getElementById ( "timeRemaining" ) ;
1919 const input = document . getElementById ( "alarmSet" ) ;
2020
21- totalSeconds = Math . max ( 0 , totalSeconds ) ;
2221 const formatted = formatTime ( totalSeconds ) ;
2322
2423 input . value = formatted ;
2524 heading . innerHTML = `Time Remaining:<br><br>${ formatted } ` ;
2625}
2726
2827function incrementTime ( amount ) {
29- totalSeconds = Math . max ( 0 , totalSeconds + amount ) ;
28+ totalSeconds += amount ;
29+ if ( totalSeconds < 0 ) totalSeconds = 0 ;
3030 updateDisplay ( ) ;
3131}
3232
@@ -51,16 +51,22 @@ function setAlarm() {
5151 totalSeconds = parsed ;
5252 updateDisplay ( ) ;
5353
54- timer = setInterval ( ( ) => {
55- totalSeconds -- ;
56- totalSeconds = Math . max ( 0 , totalSeconds ) ;
57- updateDisplay ( ) ;
54+ if ( totalSeconds === 0 ) {
55+ playAlarm ( ) ;
56+ return ;
57+ } //Alarm plays immediately if time is set to 00:00
5858
59- if ( totalSeconds === 0 ) {
59+ timer = setInterval ( ( ) => {
60+ totalSeconds -= 1 ;
61+ if ( totalSeconds <= 0 ) {
62+ totalSeconds = 0 ;
63+ updateDisplay ( ) ;
6064 clearInterval ( timer ) ;
6165 timer = null ;
6266 playAlarm ( ) ;
67+ return ;
6368 }
69+ updateDisplay ( ) ;
6470 } , 1000 ) ;
6571}
6672
You can’t perform that action at this time.
0 commit comments