Skip to content

Commit 0f1d940

Browse files
committed
alarmclock with extras
1 parent 5326a26 commit 0f1d940

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function setAlarm() {
4242
if (inputInfo <= 0) {
4343
clearInterval(intervalId);
4444
playAlarm();
45-
changeBackgroundColor();
45+
changeBackgroundColorFlashing();
4646
return;
4747
} else {
4848
inputInfo--;
@@ -57,16 +57,27 @@ function setAlarm() {
5757
//console.log("click event is firing...");
5858
//});
5959

60-
//setStopButton.addEventListener("click", function stopAlarm() {
61-
//console.log("click event is firing...");
62-
//clearInterval(intervalId);
63-
//pauseAlarm();
64-
//});
65-
66-
//alarm sound stop})
67-
68-
function changeBackgroundColor() {
69-
backgroundColor.style.backgroundColor = "lightblue";
60+
setStopButton.addEventListener("click", function stopFlashing() {
61+
console.log("click event is firing...");
62+
clearInterval(flashIntervalId);
63+
backgroundColor.style.backgroundColor = "";
64+
pauseAlarm();
65+
});
66+
67+
//function changeBackgroundColor() {
68+
//backgroundColor.style.backgroundColor = "lightblue";
69+
//}
70+
71+
let flashColor = ["yellow", "pink", "lightgrey", "green"];
72+
let flashIntervalId;
73+
let colorIndex = 0;
74+
75+
function changeBackgroundColorFlashing() {
76+
if (flashIntervalId) clearInterval(flashIntervalId);
77+
flashIntervalId = setInterval(function () {
78+
backgroundColor.style.backgroundColor = flashColor[colorIndex];
79+
colorIndex = (colorIndex + 1) % flashColor.length;
80+
}, 1000);
7081
}
7182

7283
// DO NOT EDIT BELOW HERE

0 commit comments

Comments
 (0)