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 countdownInterval ;
2+
3+ function setAlarm ( ) {
4+ const inputElement = document . getElementById ( "alarmSet" ) ;
5+ const timeDisplay = document . getElementById ( "timeRemaining" ) ;
6+
7+ let timeRemaining = parseInt ( inputElement . value , 10 ) || 0 ;
8+
9+ clearInterval ( countdownInterval ) ;
10+
11+ function updateDisplay ( ) {
12+ const minutes = String ( Math . floor ( timeRemaining / 60 ) ) . padStart ( 2 , "0" ) ;
13+ const seconds = String ( timeRemaining % 60 ) . padStart ( 2 , "0" ) ;
14+ timeDisplay . innerText = `Time Remaining: ${ minutes } :${ seconds } ` ;
15+ }
16+
17+ updateDisplay ( ) ;
18+
19+ countdownInterval = setInterval ( ( ) => {
20+ timeRemaining -- ;
21+
22+ if ( timeRemaining < 0 ) {
23+ clearInterval ( countdownInterval ) ;
24+ playAlarm ( ) ;
25+ } else {
26+ updateDisplay ( ) ;
27+ }
28+ } , 1000 ) ;
29+ }
230
331// DO NOT EDIT BELOW HERE
432
Original file line number Diff line number Diff line change 1- <!DOCTYPE html>
1+ <!doctype html>
22< html lang ="en ">
33 < head >
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 ">
1111 < h1 id ="timeRemaining "> Time Remaining: 00:00</ h1 >
1212 < label for ="alarmSet "> Set time to:</ label >
13- < input id ="alarmSet " type ="number " />
13+ < input id ="alarmSet " type ="number " min =" 0 " />
1414
1515 < button id ="set " type ="button "> Set Alarm</ button >
1616 < button id ="stop " type ="button "> Stop Alarm</ button >
You can’t perform that action at this time.
0 commit comments