File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
1+ let timerId = null ;
2+ let remainingSeconds = 0 ;
3+
4+ function updateDisplay ( ) {
5+ let minutes = String ( Math . floor ( remainingSeconds / 60 ) ) . padStart ( 2 , "0" ) ;
6+ let seconds = String ( remainingSeconds % 60 ) . padStart ( 2 , "0" ) ;
7+ document . getElementById (
8+ "timeRemaining"
9+ ) . textContent = `Time Remaining: ${ minutes } :${ seconds } ` ;
10+ }
11+
12+ function startCountdown ( ) {
13+ timerId = setInterval ( ( ) => {
14+ remainingSeconds -= 1 ;
15+ updateDisplay ( ) ;
16+ if ( remainingSeconds === 0 ) {
17+ remainingSeconds = 0 ;
18+ clearInterval ( timerId ) ;
19+ timerId = null ;
20+ playAlarm ( ) ;
21+ }
22+ } , 1000 ) ;
23+ }
24+
25+ function setAlarm ( ) {
26+ const input = document . getElementById ( "alarmSet" ) ;
27+ const inputValue = Number ( input . value ) ;
28+ clearInterval ( timerId ) ;
29+ timerId = null ;
30+ remainingSeconds = inputValue ;
31+
32+ updateDisplay ( ) ;
33+ startCountdown ( ) ;
34+ }
235
336// DO NOT EDIT BELOW HERE
437
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 ">
You can’t perform that action at this time.
0 commit comments