File tree Expand file tree Collapse file tree 2 files changed +44
-3
lines changed
Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
1+ const alarmInput = document . getElementById ( "alarmSet" ) ;
2+ const timeRemaining = document . getElementById ( "timeRemaining" ) ;
3+ const setButton = document . getElementById ( "set" ) ;
4+ const stopButton = document . getElementById ( "stop" ) ;
5+
6+ let counter ;
7+
8+ setButton . addEventListener ( "click" , setAlarm ) ;
9+ stopButton . addEventListener ( "click" , pauseAlarm ) ;
10+
11+ function setText ( ) {
12+ const alarmValue = parseInt ( alarmInput . value ) || 0 ;
13+
14+ const minutes = Math . floor ( alarmValue / 60 ) ;
15+ const seconds = alarmValue % 60 ;
16+
17+ const displayM = String ( minutes ) . padStart ( 2 , "0" ) ;
18+ const displayS = String ( seconds ) . padStart ( 2 , "0" ) ;
19+
20+ timeRemaining . textContent = `Time Remaining: ${ displayM } :${ displayS } ` ;
21+ }
22+
23+ function countdown ( ) {
24+ let alarmValue = parseInt ( alarmInput . value ) || 0 ;
25+
26+ if ( alarmValue <= 0 ) {
27+ playAlarm ( ) ;
28+ clearInterval ( counter ) ;
29+ return ;
30+ }
31+
32+ alarmInput . value = alarmValue - 1 ;
33+ setText ( ) ;
34+ }
35+
36+ function setAlarm ( ) {
37+ clearInterval ( counter ) ;
38+
39+ setText ( ) ;
40+
41+ counter = setInterval ( countdown , 1000 ) ;
42+ }
243
344// DO NOT EDIT BELOW HERE
445
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 ">
You can’t perform that action at this time.
0 commit comments