File tree Expand file tree Collapse file tree 3 files changed +7234
-2
lines changed
Expand file tree Collapse file tree 3 files changed +7234
-2
lines changed Original file line number Diff line number Diff line change 1- function setAlarm ( ) { }
1+ let countDown ;
2+ let remainingSeconds = 0 ;
3+
4+ function setAlarm ( ) {
5+ let timeRemaining = document . getElementById ( "timeRemaining" ) ;
6+ let alarmSet = document . getElementById ( "alarmSet" ) . value ;
7+ remainingSeconds = Number ( alarmSet ) ;
8+ if ( isNaN ( remainingSeconds ) || remainingSeconds <= 0 ) {
9+ prompt ( "please enter a value greater than zero!" ) ;
10+ return ;
11+ }
12+ displayTime ( ) ;
13+ countDown = setInterval ( timer , 1000 ) ;
14+ }
15+
16+ function displayTime ( ) {
17+ let timeRemaining = document . getElementById ( "timeRemaining" ) ;
18+ let hour = Math . floor ( remainingSeconds / 3600 ) ;
19+ let minutes = Math . floor ( ( remainingSeconds % 3600 ) / 60 ) ;
20+ let seconds = Math . floor ( remainingSeconds % 60 ) ;
21+
22+ if ( minutes < 10 ) {
23+ minutes = "0" + minutes ;
24+ }
25+ if ( seconds < 10 ) {
26+ seconds = "0" + seconds ;
27+ }
28+
29+ if ( hour > 0 ) {
30+ timeRemaining . textContent = `Time Remaining: ${ hour } :${ minutes } :${ seconds } ` ;
31+ } else {
32+ timeRemaining . textContent = `Time Remaining: ${ minutes } :${ seconds } ` ;
33+ }
34+ }
35+
36+ function timer ( ) {
37+ remainingSeconds -- ;
38+ displayTime ( ) ;
39+ if ( remainingSeconds <= 0 ) {
40+ clearInterval ( countDown ) ;
41+ playAlarm ( ) ;
42+ }
43+ }
244
345// DO NOT EDIT BELOW HERE
446
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