File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11let countdown = null ;
22
3+ function resetAlarm ( ) {
4+ clearInterval ( countdown ) ;
5+ countdown = null ;
6+ pauseAlarm ( ) ;
7+ updateHeading ( 0 ) ;
8+ }
9+
310function setAlarm ( ) {
411 const input = document . getElementById ( "alarmSet" ) ;
512 let time = Number ( input . value ) ;
613
7- const heading = document . getElementById ( "timeRemaining" ) ;
14+ if ( isNaN ( time ) || time < 0 ) {
15+ updateHeading ( 0 ) ;
16+ return ;
17+ }
818
9- if ( countdown ) {
10- clearInterval ( countdown ) ;
19+ resetAlarm ( ) ;
20+
21+ if ( time === 0 ) {
22+ updateHeading ( 0 ) ;
23+ playAlarm ( ) ;
24+ return ;
1125 }
1226
13- updateHeading ( time , heading ) ;
27+ updateHeading ( time ) ;
1428
1529 countdown = setInterval ( ( ) => {
1630 time -- ;
1731
1832 if ( time <= 0 ) {
19- updateHeading ( 0 , heading ) ;
33+ updateHeading ( 0 ) ;
2034 clearInterval ( countdown ) ;
2135 playAlarm ( ) ;
2236 } else {
23- updateHeading ( time , heading ) ;
37+ updateHeading ( time ) ;
2438 }
2539 } , 1000 ) ;
2640}
2741
28- function updateHeading ( time , heading ) {
42+ function updateHeading ( time ) {
43+ const heading = document . getElementById ( "timeRemaining" ) ;
44+
2945 const minutes = Math . floor ( time / 60 ) ;
3046 const seconds = time % 60 ;
3147
You can’t perform that action at this time.
0 commit comments