File tree Expand file tree Collapse file tree 1 file changed +19
-20
lines changed
Expand file tree Collapse file tree 1 file changed +19
-20
lines changed Original file line number Diff line number Diff line change @@ -43,32 +43,31 @@ function setAlarm() {
4343
4444 // Clear previous countdown
4545 function resetAlarmState ( ) {
46- clearInterval ( timer ) ;
47- clearInterval ( flashing ) ;
48- flashing = null ;
49- document . body . style . backgroundColor = "" ;
50- pauseAlarm ( ) ;
51- audio . currentTime = 0 ;
52- }
53-
54- resetAlarmState ( ) ;
46+ clearInterval ( timer ) ;
47+ clearInterval ( flashing ) ;
48+ flashing = null ;
49+ document . body . style . backgroundColor = "" ;
50+ pauseAlarm ( ) ;
51+ audio . currentTime = 0 ;
52+ }
5553
54+ resetAlarmState ( ) ;
5655
57- function tick ( ) {
58- if ( timeLeft > 0 ) {
56+ if ( timeLeft === 0 ) {
57+ // Special case: alarm should start immediately
58+ startAlarm ( ) ;
59+ } else {
60+ timer = setInterval ( ( ) => {
5961 timeLeft -- ;
6062 updateDisplay ( timeLeft ) ;
61- } else {
62- clearInterval ( timer ) ;
63- startAlarm ( ) ;
64- }
65- }
6663
67- // Run once immediately for consistency
68- tick ( ) ;
69- timer = setInterval ( tick , 1000 ) ;
64+ if ( timeLeft === 0 ) {
65+ clearInterval ( timer ) ;
66+ startAlarm ( ) ;
67+ }
68+ } , 1000 ) ;
69+ }
7070}
71-
7271function updateDisplay ( seconds ) {
7372 const mins = String ( Math . floor ( seconds / 60 ) ) . padStart ( 2 , "0" ) ;
7473 const secs = String ( seconds % 60 ) . padStart ( 2 , "0" ) ;
You can’t perform that action at this time.
0 commit comments