File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
1+ function setAlarm ( ) {
2+ let timeRemaining = document . getElementById ( "alarmSet" ) . value ;
3+ const timeDisplay = document . getElementById ( "timeRemaining" ) ;
4+
5+ // Create a reusable function to update the text on the screen
6+ const updateDisplay = ( time ) => {
7+ let minutes = Math . floor ( time / 60 )
8+ . toString ( )
9+ . padStart ( 2 , "0" ) ;
10+ let seconds = ( time % 60 ) . toString ( ) . padStart ( 2 , "0" ) ;
11+ timeDisplay . innerText = "Time Remaining: " + minutes + ":" + seconds ;
12+ } ;
13+
14+ // STEP 1: Display the starting time IMMEDIATELY
15+ updateDisplay ( timeRemaining ) ;
16+
17+ // STEP 2: Start the interval
18+ const countdown = setInterval ( ( ) => {
19+ timeRemaining -- ;
20+ updateDisplay ( timeRemaining ) ;
21+
22+ if ( timeRemaining <= 0 ) {
23+ clearInterval ( countdown ) ;
24+ playAlarm ( ) ;
25+ }
26+ } , 1000 ) ;
27+ }
228
329// DO NOT EDIT BELOW HERE
430
You can’t perform that action at this time.
0 commit comments