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 intervalId ;
2+
3+ function setAlarm ( ) {
4+ const input = document . getElementById ( "alarmSet" ) ;
5+ let time = Number ( input . value ) ;
6+
7+ const heading = document . getElementById ( "timeRemaining" ) ;
8+
9+ clearInterval ( intervalId ) ;
10+
11+ function format ( num ) {
12+ if ( num < 10 ) return "0" + num ;
13+ return num ;
14+ }
15+
16+ heading . innerText =
17+ "Time Remaining: " +
18+ format ( Math . floor ( time / 60 ) ) +
19+ ":" +
20+ format ( time % 60 ) ;
21+
22+ intervalId = setInterval ( ( ) => {
23+ time -- ;
24+
25+ if ( time <= 0 ) {
26+ heading . innerText = "Time Remaining: 00:00" ;
27+ clearInterval ( intervalId ) ;
28+ playAlarm ( ) ;
29+ return ;
30+ }
31+
32+ heading . innerText =
33+ "Time Remaining: " +
34+ format ( Math . floor ( time / 60 ) ) +
35+ ":" +
36+ format ( time % 60 ) ;
37+ } , 1000 ) ;
38+ }
239
340// DO NOT EDIT BELOW HERE
441
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 2626 "@testing-library/dom" : " ^10.4.0" ,
2727 "@testing-library/jest-dom" : " ^6.6.3" ,
2828 "@testing-library/user-event" : " ^14.6.1" ,
29- "jest" : " ^30.0.4 " ,
29+ "jest" : " ^30.2.0 " ,
3030 "jest-environment-jsdom" : " ^30.0.4"
3131 }
3232}
You can’t perform that action at this time.
0 commit comments