File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
1+ let countdownInterval = null ;
2+
3+ function setAlarm ( ) {
4+ const input = document . getElementById ( "alarmSet" ) ;
5+ let totalSeconds = parseInt ( input . value ) ;
6+
7+
8+ if ( countdownInterval ) clearInterval ( countdownInterval ) ;
9+
10+ const heading = document . getElementById ( "timeRemaining" ) ;
11+
12+ function updateHeading ( ) {
13+ const minutes = Math . floor ( totalSeconds / 60 ) ;
14+ const seconds = totalSeconds % 60 ;
15+ heading . textContent = `Time Remaining: ${ String ( minutes ) . padStart ( 2 , "0" ) } :${ String ( seconds ) . padStart ( 2 , "0" ) } ` ;
16+ }
17+
18+ updateHeading ( ) ;
19+
20+ countdownInterval = setInterval ( ( ) => {
21+ totalSeconds -- ;
22+
23+ if ( totalSeconds <= 0 ) {
24+ clearInterval ( countdownInterval ) ;
25+ playAlarm ( ) ;
26+ totalSeconds = 0 ;
27+ }
28+
29+ updateHeading ( ) ;
30+ } , 1000 ) ;
31+ }
232
333// DO NOT EDIT BELOW HERE
434
You can’t perform that action at this time.
0 commit comments