@@ -25,60 +25,65 @@ const backgroundColor = document.querySelector("html");
25
25
console . log ( backgroundColor , "<------Background Color" ) ;
26
26
27
27
let intervalId ;
28
+ let inputInfo = 0 ;
29
+
30
+ function timeFormat ( time ) {
31
+ const mins = String ( Math . floor ( time / 60 ) ) . padStart ( 2 , "0" ) ;
32
+ const seconds = String ( time % 60 ) . padStart ( 2 , "0" ) ;
33
+ timeRemainInfo . textContent = `Time Remaining: ${ mins } :${ seconds } ` ;
34
+ }
28
35
29
36
function setAlarm ( ) {
30
- let inputInfo = Number ( alarmInputArea . value ) ;
31
- if ( inputInfo < 1 ) {
32
- console . log ( "You need to input a value" ) ;
33
- window . alert ( "You need to input a value!" ) ;
37
+ inputInfo = Number ( alarmInputArea . value ) ;
38
+ if ( inputInfo < 1 || isNaN ( inputInfo ) ) {
39
+ console . log ( "You need to input a value in seconds! " ) ;
40
+ window . alert ( "You need to input a value in seconds !" ) ;
34
41
return ;
35
42
}
36
43
alarmInputArea . value = "" ;
37
- const mins = String ( Math . floor ( inputInfo / 60 ) ) . padStart ( 2 , "0" ) ;
38
- const seconds = String ( inputInfo % 60 ) . padStart ( 2 , "0" ) ;
39
- timeRemainInfo . textContent = `Time Remaining: ${ mins } :${ seconds } ` ;
44
+ timeFormat ( inputInfo ) ;
40
45
41
46
intervalId = setInterval ( function ( ) {
42
- if ( inputInfo <= 0 ) {
47
+ inputInfo -- ;
48
+ if ( inputInfo === 0 ) {
43
49
clearInterval ( intervalId ) ;
44
- playAlarm ( ) ;
50
+ timeFormat ( 0 ) ;
51
+ window . playAlarm ( ) ;
45
52
changeBackgroundColorFlashing ( ) ;
46
- return ;
47
53
} else {
48
- inputInfo -- ;
49
- const mins = String ( Math . floor ( inputInfo / 60 ) ) . padStart ( 2 , "0" ) ;
50
- const seconds = String ( inputInfo % 60 ) . padStart ( 2 , "0" ) ;
51
- timeRemainInfo . textContent = `Time Remaining: ${ mins } :${ seconds } ` ;
54
+ timeFormat ( inputInfo ) ;
52
55
}
53
56
} , 1000 ) ;
54
57
}
55
58
56
59
//setAlarmButton.addEventListener("click", function setAlarm() {
57
60
//console.log("click event is firing...");
58
61
//});
62
+ let flashColor = [ "yellow" , "pink" , "lightgrey" , "green" ] ;
63
+ let flashIntervalId ;
64
+ let colorIndex = 0 ;
59
65
60
66
setStopButton . addEventListener ( "click" , function stopFlashing ( ) {
61
67
console . log ( "click event is firing..." ) ;
62
68
clearInterval ( flashIntervalId ) ;
63
69
backgroundColor . style . backgroundColor = "" ;
64
- pauseAlarm ( ) ;
70
+ window . pauseAlarm ( ) ;
65
71
} ) ;
66
72
67
73
//function changeBackgroundColor() {
68
74
//backgroundColor.style.backgroundColor = "lightblue";
69
75
//}
70
76
71
- let flashColor = [ "yellow" , "pink" , "lightgrey" , "green" ] ;
72
- let flashIntervalId ;
73
- let colorIndex = 0 ;
74
-
75
77
function changeBackgroundColorFlashing ( ) {
76
78
if ( flashIntervalId ) clearInterval ( flashIntervalId ) ;
77
79
flashIntervalId = setInterval ( function ( ) {
78
80
backgroundColor . style . backgroundColor = flashColor [ colorIndex ] ;
79
81
colorIndex = ( colorIndex + 1 ) % flashColor . length ;
80
82
} , 1000 ) ;
83
+ //stopFlashing();
81
84
}
85
+ window . playAlarm = playAlarm ;
86
+ window . pauseAlarm = pauseAlarm ;
82
87
83
88
// DO NOT EDIT BELOW HERE
84
89
0 commit comments