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