File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11var audio = new Audio ( "alarmsound.mp3" ) ;
22
3- let timeRemaining = 0 ;
3+ let timeRemaining = 0 ;
44let countdownInterval = null ;
5- let hasPlayed = false ;
65
76function setAlarm ( ) {
87 const input = document . getElementById ( "alarmSet" ) . value ;
@@ -14,7 +13,6 @@ function setAlarm() {
1413 return ;
1514 }
1615
17- hasPlayed = false ;
1816 updateDisplay ( ) ;
1917
2018 if ( countdownInterval ) {
@@ -24,22 +22,14 @@ function setAlarm() {
2422 countdownInterval = setInterval ( ( ) => {
2523 timeRemaining -- ;
2624
27- // Play alarm at 10 seconds remaining (or immediately if less than 10)
28- if ( ! hasPlayed && ( timeRemaining === 10 || timeRemaining < 10 ) ) {
29- playAlarm ( ) ;
30- hasPlayed = true ;
31- }
25+ updateDisplay ( ) ;
3226
3327 if ( timeRemaining <= 0 ) {
34- timeRemaining = 0 ;
35- updateDisplay ( ) ;
3628 clearInterval ( countdownInterval ) ;
37- return ;
29+ playAlarm ( ) ;
3830 }
39-
40- updateDisplay ( ) ;
4131 } , 1000 ) ;
42- } // ✅ properly closed function
32+ }
4333
4434function updateDisplay ( ) {
4535 const display = document . getElementById ( "timeRemaining" ) ;
@@ -68,4 +58,4 @@ function pauseAlarm() {
6858 }
6959}
7060
71- window . onload = setup ;
61+ window . onload = setup ;
You can’t perform that action at this time.
0 commit comments