File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed
Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
1+ function setScreenTimer ( totalSeconds ) {
2+ const minutes = Math . floor ( totalSeconds / 60 ) ;
3+ const seconds = totalSeconds % 60 ;
4+ const timeRemainingSpan = document . querySelector ( "#timeRemaining span" ) ;
5+ timeRemainingSpan . textContent = `${ String ( minutes ) . padStart ( 2 , "0" ) } :${ String ( seconds ) . padStart ( 2 , "0" ) } ` ;
6+ }
7+
8+ function setAlarm ( ) {
9+ const alarmSet = document . getElementById ( "alarmSet" ) ;
10+ let totalSeconds = Number ( alarmSet . value ) ;
11+
12+ setScreenTimer ( totalSeconds ) ;
13+
14+ const timer = setInterval ( ( ) => {
15+ totalSeconds -- ;
16+ if ( totalSeconds <= 0 ) {
17+ setScreenTimer ( 0 ) ;
18+ clearInterval ( timer ) ;
19+ playAlarm ( ) ;
20+ } else {
21+ setScreenTimer ( totalSeconds ) ;
22+ }
23+ } , 1000 ) ;
24+ }
225
326// DO NOT EDIT BELOW HERE
427
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 ">
11- < h1 id ="timeRemaining "> Time Remaining: 00:00</ h1 >
11+ < h1 id ="timeRemaining "> Time Remaining: < span > 00:00</ span > </ h1 >
1212 < label for ="alarmSet "> Set time to:</ label >
1313 < input id ="alarmSet " type ="number " />
1414
1515 < button id ="set " type ="button "> Set Alarm</ button >
1616 < button id ="stop " type ="button "> Stop Alarm</ button >
1717 </ div >
18- < script src ="alarmclock.js "> </ script >
18+ < script src ="alarmclock.js " defer > </ script >
1919 </ body >
2020</ html >
You can’t perform that action at this time.
0 commit comments