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+ function setAlarm ( ) {
2+ const input = document . getElementById ( "alarmSet" ) ;
3+ const heading = document . getElementById ( "timeRemaining" ) ;
4+
5+ let remainingSeconds = Number ( input . value ) ;
6+
7+ function formatTime ( totalSeconds ) {
8+ const minutes = Math . floor ( totalSeconds / 60 ) ;
9+ const seconds = totalSeconds % 60 ;
10+
11+ const mm = String ( minutes ) . padStart ( 2 , "0" ) ;
12+ const ss = String ( seconds ) . padStart ( 2 , "0" ) ;
13+
14+ return `${ mm } :${ ss } ` ;
15+ }
16+
17+ heading . innerText = `Time Remaining: ${ formatTime ( remainingSeconds ) } ` ;
18+
19+ const intervalId = setInterval ( ( ) => {
20+ remainingSeconds -= 1 ;
21+
22+ if ( remainingSeconds > 0 ) {
23+ heading . innerText = `Time Remaining: ${ formatTime ( remainingSeconds ) } ` ;
24+ } else {
25+ heading . innerText = "Time Remaining: 00:00" ;
26+ clearInterval ( intervalId ) ;
27+ playAlarm ( ) ;
28+ document . body . classList . add ( "flash" ) ;
29+ }
30+ } , 1000 ) ;
31+ }
32+
33+ function stopFlashingBackground ( ) {
34+ document . body . classList . remove ( "flash" ) ;
35+ }
236
337// DO NOT EDIT BELOW HERE
438
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 ">
Original file line number Diff line number Diff line change 1313h1 {
1414 text-align : center;
1515}
16+
17+ . flash {
18+ animation : flash-bg 0.5s infinite alternate;
19+ }
20+
21+ @keyframes flash-bg {
22+ from { background-color : white; }
23+ to { background-color : red; }
24+ }
25+
You can’t perform that action at this time.
0 commit comments