File tree Expand file tree Collapse file tree 2 files changed +15
-15
lines changed
Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Original file line number Diff line number Diff line change 1+ function updateDisplay ( heading , time ) {
2+ const minutes = String ( Math . floor ( time / 60 ) ) . padStart ( 2 , "0" ) ;
3+ const seconds = String ( time % 60 ) . padStart ( 2 , "0" ) ;
4+ heading . innerText = `Time Remaining: ${ minutes } :${ seconds } ` ;
5+ }
6+
17function setAlarm ( ) {
28 let time = Number ( document . getElementById ( "alarmSet" ) . value ) ;
39 const heading = document . getElementById ( "timeRemaining" ) ;
410
511 audio . loop = true ;
6-
712 document . body . style . backgroundColor = "" ;
813
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 ) ;
14+ updateDisplay ( heading , time ) ;
1615
1716 const intervalId = setInterval ( ( ) => {
1817 time -- ;
1918
2019 if ( time <= 0 ) {
2120 clearInterval ( intervalId ) ;
22- updateDisplay ( 0 ) ;
21+ updateDisplay ( heading , 0 ) ;
2322
2423 document . body . style . backgroundColor = "red" ;
2524
2625 playAlarm ( ) ;
27-
2826 } else {
29- updateDisplay ( time ) ;
27+ updateDisplay ( heading , time ) ;
3028 }
3129 } , 1000 ) ;
3230}
@@ -54,4 +52,4 @@ function pauseAlarm() {
5452 audio . pause ( ) ;
5553}
5654
57- window . onload = setup ;
55+ 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 > Alarm clock app </ title >
7+ < title > Alarm Clock App </ title >
88 </ head >
99 < body >
1010 < div class ="centre ">
1111 < h1 id ="timeRemaining "> Time Remaining: 00:00</ h1 >
12- < label for ="alarmSet "> Set time to:</ label >
13- < input id ="alarmSet " type ="number " />
12+
13+ < label for ="alarmSet "> Set time (seconds):</ label >
14+ < input id ="alarmSet " type ="number " min ="0 " />
1415
1516 < button id ="set " type ="button "> Set Alarm</ button >
1617 < button id ="stop " type ="button "> Stop Alarm</ button >
1718 </ div >
19+
1820 < script src ="alarmclock.js "> </ script >
1921 </ body >
2022</ html >
You can’t perform that action at this time.
0 commit comments