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 countdown = null ;
22
3+ function setAlarm ( ) {
4+ const input = document . getElementById ( "alarmSet" ) ;
5+ let time = Number ( input . value ) ;
6+
7+ const heading = document . getElementById ( "timeRemaining" ) ;
8+
9+ if ( countdown ) {
10+ clearInterval ( countdown ) ;
11+ }
12+
13+ updateHeading ( time , heading ) ;
14+
15+ countdown = setInterval ( ( ) => {
16+ time -- ;
17+
18+ if ( time <= 0 ) {
19+ updateHeading ( 0 , heading ) ;
20+ clearInterval ( countdown ) ;
21+ playAlarm ( ) ;
22+ } else {
23+ updateHeading ( time , heading ) ;
24+ }
25+ } , 1000 ) ;
26+ }
27+
28+ function updateHeading ( time , heading ) {
29+ const minutes = Math . floor ( time / 60 ) ;
30+ const seconds = time % 60 ;
31+
32+ const mm = String ( minutes ) . padStart ( 2 , "0" ) ;
33+ const ss = String ( seconds ) . padStart ( 2 , "0" ) ;
34+
35+ heading . innerText = `Time Remaining: ${ mm } :${ ss } ` ;
36+ }
337// DO NOT EDIT BELOW HERE
438
539var audio = new Audio ( "alarmsound.mp3" ) ;
You can’t perform that action at this time.
0 commit comments