1- botton = document . getElementById ( "set" ) ;
1+ const startButton = document . getElementById ( "set" ) ;
2+ const pause = document . getElementById ( "stop" ) ;
3+ pause . hidden = true ;
24//begins the count down
3- botton . addEventListener ( "click" , setAlarm ) ;
45
56// document.getElementById("set").addEventListener("click", setAlarm);
67const timeRemaining = document . getElementById ( "timeRemaining" ) ;
78function setAlarm ( ) {
89 // gets the value of the input field and stores it in a variable
910 let timeInSeconds = document . getElementById ( "alarmSet" ) . value ;
10- botton . disabled = true ;
11-
1211 let clock = setInterval ( ( ) => {
1312 function pad ( num ) {
1413 return num . toString ( ) . padStart ( 2 , "0" ) ;
@@ -22,16 +21,27 @@ function setAlarm() {
2221
2322 return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
2423 }
25-
26- timeInSecond = timeInSeconds -- ;
27- if ( timeInSeconds == 0 ) {
24+ startButton . hidden = true ;
25+ pause . hidden = false ;
26+ timeInSeconds -- ;
27+ if ( timeInSeconds <= 0 ) {
2828 clearInterval ( clock ) ;
2929 playAlarm ( ) ;
30- botton . disabled = false ;
3130 }
31+
3232 timeRemaining . innerHTML =
3333 "time remaining " + formatTimeDisplay ( timeInSeconds ) ;
3434 } , 1000 ) ;
35+ startButton . addEventListener ( "click" , setAlarm ) ;
36+ pause . addEventListener ( "click" , pauseWhenRunning ) ;
37+
38+ function pauseWhenRunning ( ) {
39+ startButton . hidden = false ;
40+ pause . hidden = true ;
41+ clearInterval ( clock ) ;
42+ document . getElementById ( "alarmSet" ) . value = timeInSeconds ;
43+ audio . pause ( ) ;
44+ }
3545}
3646
3747// DO NOT EDIT BELOW HERE
0 commit comments