File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed
Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
1+ function setAlarm ( ) {
2+ let time = Number ( document . getElementById ( "alarmSet" ) . value ) ;
3+ const heading = document . getElementById ( "timeRemaining" ) ;
4+
5+ audio . loop = true ;
6+
7+ document . body . style . backgroundColor = "" ;
8+
9+ function updateDisplay ( t ) {
10+ const minutes = String ( Math . floor ( t / 60 ) ) . padStart ( 2 , "0" ) ;
11+ const seconds = String ( t % 60 ) . padStart ( 2 , "0" ) ;
12+ heading . innerText = `Time Remaining: ${ minutes } :${ seconds } ` ;
13+ }
14+
15+ updateDisplay ( time ) ;
16+
17+ const intervalId = setInterval ( ( ) => {
18+ time -- ;
19+
20+ if ( time <= 0 ) {
21+ clearInterval ( intervalId ) ;
22+ updateDisplay ( 0 ) ;
23+
24+ document . body . style . backgroundColor = "red" ;
25+
26+ playAlarm ( ) ;
27+
28+ } else {
29+ updateDisplay ( time ) ;
30+ }
31+ } , 1000 ) ;
32+ }
33+
234
335// DO NOT EDIT BELOW HERE
436
@@ -22,4 +54,4 @@ function pauseAlarm() {
2254 audio . pause ( ) ;
2355}
2456
25- window . onload = setup ;
57+ window . onload = setup ;
Original file line number Diff line number Diff line change 44 < meta charset ="utf-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
66 < link rel ="stylesheet " href ="style.css " />
7- < title > Title here </ title >
7+ < title > Alarm clock app </ title >
88 </ head >
99 < body >
1010 < div class ="centre ">
You can’t perform that action at this time.
0 commit comments