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+ let totalSeconds = parseInt ( input . value ) || 0 ;
5+
6+ function updateDisplay ( ) {
7+ const minutes = Math . floor ( totalSeconds / 60 ) ;
8+ const seconds = totalSeconds % 60 ;
9+ heading . innerText = `Time Remaining: ${ minutes . toString ( ) . padStart ( 2 , '0' ) } :${ seconds . toString ( ) . padStart ( 2 , '0' ) } ` ;
10+
11+ if ( totalSeconds > 0 ) {
12+ totalSeconds -- ;
13+ } else {
14+ playAlarm ( ) ;
15+ clearInterval ( intervalId ) ; // Stop interval after alarm
16+ }
17+ }
18+
19+ updateDisplay ( ) ; // Set initial time
20+ const intervalId = setInterval ( updateDisplay , 1000 ) ;
21+ }
22+
223
324// DO NOT EDIT BELOW HERE
425
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 1313 "bugs" : {
1414 "url" : " https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
1515 },
16- "homepage" : " https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
16+ "homepage" : " https://github.com/CodeYourFuture/CYF-Coursework-Template#readme" ,
17+ "devDependencies" : {
18+ "@jest/globals" : " ^30.3.0" ,
19+ "jest" : " ^30.3.0" ,
20+ "jsdom" : " ^26.1.0"
21+ }
1722}
You can’t perform that action at this time.
0 commit comments