File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,32 @@ function setAlarm() {
1414 if ( timerInterval ) {
1515 clearInterval ( timerInterval ) ;
1616 }
17+ // Function to render the formatted time (MM:SS) to the DOM
18+ function updateDisplay ( ) {
19+ const minutes = Math . floor ( totalSeconds / 60 ) ;
20+ const seconds = totalSeconds % 60 ;
21+
22+ const formattedMinutes = String ( minutes ) . padStart ( 2 , "0" ) ;
23+ const formattedSeconds = String ( seconds ) . padStart ( 2 , "0" ) ;
24+
25+ timeRemainingEl . innerText = `Time Remaining: ${ formattedMinutes } :${ formattedSeconds } ` ;
26+ }
27+ // 1. Immediately set heading on button click
28+ updateDisplay ( ) ;
29+
30+ // 2. Start the countdown timer
31+ timerInterval = setInterval ( ( ) => {
32+ totalSeconds -= 1 ;
33+
34+ if ( totalSeconds >= 0 ) {
35+ updateDisplay ( ) ;
36+ }
37+
38+ if ( totalSeconds === 0 ) {
39+ playAlarm ( ) ;
40+ clearInterval ( timerInterval ) ;
41+ }
42+ } , 1000 ) ;
1743}
1844
1945// DO NOT EDIT BELOW HERE
You can’t perform that action at this time.
0 commit comments