@@ -3,7 +3,7 @@ const display = document.querySelector("#timeRemaining");
33const totalSeconds = document . querySelector ( "#alarmSet" ) ;
44const setButton = document . querySelector ( "#set" ) ;
55const stopButton = document . querySelector ( "#stop" ) ;
6- let conuntdownInterval ;
6+ let countDownInterval ;
77
88function formatTime ( totalSeconds ) {
99 const minutes = Math . floor ( totalSeconds / 60 ) ;
@@ -15,48 +15,47 @@ function formatTime(totalSeconds) {
1515}
1616
1717function reset ( ) {
18- clearInterval ( conuntdownInterval ) ;
18+ clearInterval ( countDownInterval ) ;
1919 display . textContent = "Time Remaining: 00:00" ;
2020 display . style . color = "black" ;
2121 setButton . disabled = false ;
2222 document . body . style . background = "" ;
2323}
24- let countdownInterval ;
24+
2525setButton . addEventListener ( "click" , ( ) => {
26- let timeleft = Number ( totalSeconds . value ) ;
26+ let timeLeft = Number ( totalSeconds . value ) ;
2727
28- if ( timeleft <= 0 || isNaN ( timeleft ) ) {
28+ if ( timeLeft <= 0 || isNaN ( timeLeft ) ) {
2929 alert ( "please enter a number greater than zero (0)!" ) ;
3030 return ;
3131 }
3232 setButton . disabled = true ;
3333
34- display . textContent = formatTime ( timeleft ) ;
35-
3634 const warningTime = 10 ; // seconds
37- clearInterval ( conuntdownInterval ) ;
3835
39- conuntdownInterval = setInterval ( ( ) => {
40- timeleft -- ;
36+ display . textContent = formatTime ( timeLeft ) ;
37+ countDownInterval = setInterval ( ( ) => {
38+ display . textContent = formatTime ( timeLeft ) ;
39+ timeLeft -- ;
4140
42- if ( timeleft >= 0 ) {
43- display . textContent = formatTime ( timeleft ) ;
41+ if ( timeLeft >= 0 ) {
42+ display . textContent = formatTime ( timeLeft ) ;
4443 }
4544
46- if ( timeleft <= warningTime ) {
45+ if ( timeLeft <= warningTime ) {
4746 display . style . color = "red" ;
4847 }
4948
50- if ( timeleft <= 0 ) {
51- clearInterval ( conuntdownInterval ) ;
49+ if ( timeLeft <= 0 ) {
50+ clearInterval ( countDownInterval ) ;
5251 document . body . style . backgroundColor = "grey" ;
5352 playAlarm ( ) ;
5453 }
5554 } , 1000 ) ;
5655} ) ;
5756
5857stopButton . addEventListener ( "click" , ( ) => {
59- clearInterval ( conuntdownInterval ) ;
58+ clearInterval ( countDownInterval ) ;
6059 reset ( ) ;
6160 pauseAlarm ( ) ;
6261} ) ;
@@ -69,10 +68,6 @@ function setup() {
6968 document . getElementById ( "set" ) . addEventListener ( "click" , ( ) => {
7069 setAlarm ( ) ;
7170 } ) ;
72-
73- document . getElementById ( "stop" ) . addEventListener ( "click" , ( ) => {
74- pauseAlarm ( ) ;
75- } ) ;
7671}
7772
7873function playAlarm ( ) {
0 commit comments