File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -7,9 +7,13 @@ function formatTime(seconds) {
77 return `${ mins } :${ secs } ` ;
88}
99
10+ function updateDisplay ( timeLeft ) {
11+ const display = document . getElementById ( "timeRemaining" ) ;
12+ display . textContent = `Time Remaining: ${ formatTime ( timeLeft ) } ` ;
13+ }
14+
1015function setAlarm ( ) {
1116 const input = document . getElementById ( "alarmSet" ) . value ;
12- const display = document . getElementById ( "timeRemaining" ) ;
1317
1418 timeLeft = parseInt ( input , 10 ) ;
1519
@@ -18,15 +22,16 @@ function setAlarm() {
1822 return ;
1923 }
2024
21- display . textContent = `Time Remaining: ${ formatTime ( timeLeft ) } ` ;
22-
2325 if ( timer ) {
2426 clearInterval ( timer ) ;
2527 }
28+
29+ updateDisplay ( timeLeft ) ;
30+
2631 timer = setInterval ( ( ) => {
2732 if ( timeLeft > 0 ) {
2833 timeLeft -- ;
29- display . textContent = `Time Remaining: ${ formatTime ( timeLeft ) } ` ;
34+ updateDisplay ( timeLeft ) ;
3035 } else {
3136 clearInterval ( timer ) ;
3237 playAlarm ( ) ;
You can’t perform that action at this time.
0 commit comments