@@ -18,7 +18,6 @@ function updateDisplay() {
1818 const heading = document . getElementById ( "timeRemaining" ) ;
1919 const input = document . getElementById ( "alarmSet" ) ;
2020
21- // clamp BEFORE formatting
2221 totalSeconds = Math . max ( 0 , totalSeconds ) ;
2322 const formatted = formatTime ( totalSeconds ) ;
2423
@@ -27,7 +26,6 @@ function updateDisplay() {
2726}
2827
2928function incrementTime ( amount ) {
30- // correctly ADD or SUBTRACT 5 seconds
3129 totalSeconds = Math . max ( 0 , totalSeconds + amount ) ;
3230 updateDisplay ( ) ;
3331}
@@ -48,7 +46,7 @@ function setAlarm() {
4846
4947 timer = setInterval ( ( ) => {
5048 totalSeconds -- ;
51- totalSeconds = Math . max ( 0 , totalSeconds ) ; // clamp again for safety
49+ totalSeconds = Math . max ( 0 , totalSeconds ) ;
5250 updateDisplay ( ) ;
5351
5452 if ( totalSeconds === 0 ) {
@@ -67,10 +65,10 @@ function stopTimer() {
6765 audio . pause ( ) ;
6866}
6967
70- // expose to the browser
71- window . incrementTime = incrementTime ;
72- window . setAlarm = setAlarm ;
73- window . stopTimer = stopTimer ;
68+ document . getElementById ( "up" ) . addEventListener ( "click" , ( ) => incrementTime ( 5 ) ) ;
69+ document . getElementById ( "down" ) . addEventListener ( "click" , ( ) => incrementTime ( - 5 ) ) ;
70+ document . getElementById ( "set" ) . addEventListener ( "click" , setAlarm ) ;
71+ document . getElementById ( "stop" ) . addEventListener ( "click" , stopTimer ) ;
7472
7573// DO NOT EDIT BELOW HERE
7674var audio = new Audio ( "alarmsound.mp3" ) ;
0 commit comments