File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
1+ let alarmTime ;
2+ let countDown ;
3+ function setAlarm ( ) {
4+ const timeRemaining = document . getElementById ( "timeRemaining" ) ;
5+ const alarmSet = document . getElementById ( "alarmSet" ) . value ;
6+ alarmTime = parseInt ( alarmSet ) ;
7+ if ( countDown ) {
8+ clearInterval ( countDown ) ;
9+ }
10+ countDown = setInterval ( startCount , 1000 ) ;
11+ updateDisplay ( timeRemaining ) ;
12+ }
13+ function startCount ( ) {
14+ if ( alarmTime > 0 ) {
15+ alarmTime -- ;
16+ updateDisplay ( document . getElementById ( "timeRemaining" ) ) ;
17+ } else {
18+ clearInterval ( countDown ) ;
19+ playAlarm ( ) ;
20+ document . body . style . background = "#e14343" ;
21+ }
22+ }
223
24+ function updateDisplay ( timeRemainingElement ) {
25+ let minutes = Math . floor ( alarmTime / 60 ) ;
26+ let seconds = alarmTime % 60 ;
27+ timeRemainingElement . innerHTML = `Time Remaining: ${ String ( minutes ) . padStart (
28+ 2 ,
29+ "0"
30+ ) } :${ String ( seconds ) . padStart ( 2 , "0" ) } `;
31+ }
332// DO NOT EDIT BELOW HERE
433
534var audio = new Audio ( "alarmsound.mp3" ) ;
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