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+ function setAlarm ( ) {
2+ const input = document . getElementById ( "alarmSet" ) ;
3+ const heading = document . getElementById ( "timeRemaining" ) ;
4+
5+ let secondsRemaining = Number ( input . value ) ;
6+
7+ function updateDisplay ( ) {
8+ const minutes = Math . floor ( secondsRemaining / 60 ) ;
9+ const seconds = secondsRemaining % 60 ;
10+ const paddedMinutes = String ( minutes ) . padStart ( 2 , "0" ) ;
11+ const paddedSeconds = String ( seconds ) . padStart ( 2 , "0" ) ;
12+ heading . innerText = `Time Remaining: ${ paddedMinutes } :${ paddedSeconds } ` ;
13+ }
14+
15+ updateDisplay ( ) ;
16+
17+ const intervalId = setInterval ( ( ) => {
18+ secondsRemaining -- ;
19+ updateDisplay ( ) ;
20+
21+ if ( secondsRemaining <= 0 ) {
22+ clearInterval ( intervalId ) ;
23+ playAlarm ( ) ;
24+ }
25+ } , 1000 ) ;
26+ }
227
328// DO NOT EDIT BELOW HERE
429
@@ -22,4 +47,4 @@ function pauseAlarm() {
2247 audio . pause ( ) ;
2348}
2449
25- window . onload = setup ;
50+ window . onload = setup ;
You can’t perform that action at this time.
0 commit comments