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 timer = null ;
22
3- // DO NOT EDIT BELOW HERE
3+ function formatTime ( totalSeconds ) {
4+ const minutes = Math . floor ( totalSeconds / 60 ) ;
5+ const seconds = totalSeconds % 60 ;
6+ return `${ String ( minutes ) . padStart ( 2 , "0" ) } :${ String ( seconds ) . padStart ( 2 , "0" ) } ` ;
7+ }
8+
9+ function updateDisplay ( seconds ) {
10+ document . getElementById ( "timeRemaining" ) . textContent =
11+ `Time Remaining: ${ formatTime ( seconds ) } ` ;
12+ }
13+
14+ function setAlarm ( ) {
15+ if ( timer ) {
16+ clearInterval ( timer ) ;
17+ }
418
19+ let seconds = Number ( document . getElementById ( "alarmSet" ) . value ) ;
20+ updateDisplay ( seconds ) ;
21+
22+ timer = setInterval ( ( ) => {
23+ seconds -- ;
24+ updateDisplay ( seconds ) ;
25+
26+ if ( seconds <= 0 ) {
27+ clearInterval ( timer ) ;
28+ playAlarm ( ) ;
29+ }
30+ } , 1000 ) ;
31+ }
32+
33+ // DO NOT EDIT BELOW HERE
534var audio = new Audio ( "alarmsound.mp3" ) ;
635
736function setup ( ) {
@@ -22,4 +51,4 @@ function pauseAlarm() {
2251 audio . pause ( ) ;
2352}
2453
25- window . onload = setup ;
54+ 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