File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11let intervalId ;
22let isPaused ;
33let remainingSeconds = 0 ;
4+
5+ function updateCountDown ( ) {
6+ updateDisplayedTime ( remainingSeconds ) ;
7+
8+ if ( remainingSeconds <= 0 ) {
9+ finishCountDown ( ) ;
10+ return ;
11+ }
12+
13+ remainingSeconds -= 1 ;
14+ }
15+
416function setAlarm ( ) {
517 const alarmSetEl = document . getElementById ( "alarmSet" ) ;
6- let totalSeconds = + alarmSetEl . value ;
18+ const totalSeconds = + alarmSetEl . value ;
719
820 if (
921 totalSeconds <= 0 ||
@@ -15,17 +27,7 @@ function setAlarm() {
1527 }
1628 cleanInitialState ( ) ;
1729
18- function updateCountDown ( ) {
19- remainingSeconds = totalSeconds ;
20- updateDisplayedTime ( remainingSeconds ) ;
21-
22- if ( totalSeconds <= 0 ) {
23- finishCountDown ( ) ;
24- return ;
25- }
26-
27- totalSeconds -= 1 ;
28- }
30+ remainingSeconds = totalSeconds ;
2931
3032 updateCountDown ( ) ;
3133 intervalId = setInterval ( updateCountDown , 1000 ) ;
@@ -39,18 +41,8 @@ function pauseCountDown(e) {
3941 } else {
4042 e . target . textContent = "Pause" ;
4143 isPaused = false ;
42- intervalId = setInterval ( ( ) => {
43- if ( remainingSeconds <= 0 ) {
44- clearInterval ( intervalId ) ;
45- return ;
46- }
47- remainingSeconds -= 1 ;
48- updateDisplayedTime ( remainingSeconds ) ;
49-
50- if ( remainingSeconds <= 0 ) {
51- finishCountDown ( ) ;
52- }
53- } , 1000 ) ;
44+ updateCountDown ( ) ;
45+ intervalId = setInterval ( updateCountDown , 1000 ) ;
5446 }
5547}
5648
You can’t perform that action at this time.
0 commit comments