11let timer = null ;
22let secondsRemaining = 0 ;
33
4+ const timeRemainingEl = document . getElementById ( "timeRemaining" ) ;
5+ const alarmSetEl = document . getElementById ( "alarmSet" ) ;
6+ const stopButtonEl = document . getElementById ( "stop" ) ;
7+
48function formatTime ( totalSeconds ) {
59 const minutes = Math . floor ( totalSeconds / 60 ) ;
610 const seconds = totalSeconds % 60 ;
711 return `${ String ( minutes ) . padStart ( 2 , "0" ) } :${ String ( seconds ) . padStart ( 2 , "0" ) } ` ;
812}
913
1014function updateDisplay ( seconds ) {
11- document . getElementById ( "timeRemaining" ) . textContent =
12- `Time Remaining: ${ formatTime ( seconds ) } ` ;
15+ timeRemainingEl . textContent = `Time Remaining: ${ formatTime ( seconds ) } ` ;
1316}
1417
1518function setAlarm ( ) {
@@ -18,7 +21,7 @@ function setAlarm() {
1821 timer = null ;
1922 }
2023
21- const inputValue = document . getElementById ( "alarmSet" ) . value ;
24+ const inputValue = alarmSetEl . value ;
2225 const seconds = Number ( inputValue ) ;
2326
2427 if (
@@ -27,8 +30,7 @@ function setAlarm() {
2730 ! Number . isInteger ( seconds ) ||
2831 seconds <= 0
2932 ) {
30- document . getElementById ( "timeRemaining" ) . textContent =
31- "Please enter a whole number greater than 0." ;
33+ timeRemainingEl . textContent = "Please enter a whole number greater than 0." ;
3234 return ;
3335 }
3436
@@ -54,9 +56,7 @@ function stopTimer() {
5456 }
5557}
5658
57- document . addEventListener ( "DOMContentLoaded" , ( ) => {
58- document . getElementById ( "stop" ) . addEventListener ( "click" , stopTimer ) ;
59- } ) ;
59+ stopButtonEl . addEventListener ( "click" , stopTimer ) ;
6060
6161// DO NOT EDIT BELOW HERE
6262var audio = new Audio ( "alarmsound.mp3" ) ;
0 commit comments