File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const titleElement = document . getElementById ( "timeRemaining" ) ;
2+
13const ONE_SECOND_IN_MILLISECONDS = 1000 ;
24
35let timeRemainingInSeconds = 0 ;
@@ -20,15 +22,14 @@ function formatTime(totalSeconds) {
2022 * Updates the display and checks if the alarm should sound.
2123 */
2224function updateTime ( ) {
23- const titleElement = document . getElementById ( "timeRemaining" ) ;
24-
2525 timeRemainingInSeconds = timeRemainingInSeconds - 1 ;
2626 titleElement . innerText = formatTime ( timeRemainingInSeconds ) ;
2727
2828 if ( timeRemainingInSeconds === 0 ) {
2929 playAlarm ( ) ;
3030 document . body . classList . add ( "flash" ) ;
3131 clearInterval ( alarmTimerIdentifier ) ;
32+ alarmTimerIdentifier = null ; // ← reset to null for proper state management
3233 }
3334}
3435
@@ -58,7 +59,6 @@ function setAlarm() {
5859 audio . play ( ) ;
5960 audio . pause ( ) ;
6061
61- const titleElement = document . getElementById ( "timeRemaining" ) ;
6262 titleElement . innerText = formatTime ( timeRemainingInSeconds ) ;
6363
6464 alarmTimerIdentifier = setInterval ( ( ) => {
You can’t perform that action at this time.
0 commit comments