File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
21
2+ let myTimer ;
3+ function setAlarm ( ) {
4+ // fist need to get the input from the id=alarmset
5+ let setTimeSeconds = document . getElementById ( "alarmSet" ) . value ;
6+ console . log ( setTimeSeconds ) ;
7+ myTimer = setInterval ( ( ) => {
8+ const minutes = Math . trunc ( setTimeSeconds / 60 ) ;
9+ const seconds = setTimeSeconds % 60 ;
10+ console . log ( minutes ) ;
11+ // then update time remaining whith the value of alarm set
12+ const upDate = document . getElementById ( "timeRemaining" ) ;
13+ // Time Remaining: 00:00
14+ upDate . innerHTML = `Time Remaining: ${ minutes
15+ . toString ( )
16+ . padStart ( 2 , "0" ) } : ${ seconds . toString ( ) . padStart ( 2 , "0" ) } `;
17+ // Check if we get to zero
18+ if ( setTimeSeconds <= 0 ) {
19+ playAlarm ( ) ;
20+ clearInterval ( myTimer ) ;
21+ }
22+ // need tomake the functon counting donw seconds by one until get 00:00
23+ setTimeSeconds = setTimeSeconds - 1 ;
24+ } , 1000 ) ;
25+ }
326// DO NOT EDIT BELOW HERE
427
528var 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