Skip to content

Commit 4a8d0b2

Browse files
Add the new function to effect the flashing and when the stop button is click light stop flashing.
1 parent f0641bb commit 4a8d0b2

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,33 @@ function setAlarm() {
1212
timeRemaining = parseInt(input.value);
1313

1414
if (isNaN(timeRemaining) || timeRemaining <= 0) return;
15-
updateDisplay();
15+
updateDisplay();
1616

1717
interval = setInterval(() => {
1818
if (timeRemaining <= 0) {
1919
clearInterval(interval);
2020
timeRemaining = 0;
2121
updateDisplay();
2222
playAlarm();
23-
2423
// Start flashing background
25-
if (window.JEST_WORKER_ID){
2624
flashInterval = setInterval(() => {
2725
document.body.style.backgroundColor =
2826
document.body.style.backgroundColor === "green" ? "white" : "green";
2927
}, 500);
30-
31-
return; // exit interval
32-
}}
33-
// Decrement only if above 0
28+
const stopButton = document.getElementById("stop");
29+
stopButton.addEventListener(
30+
"click",
31+
() => {
32+
clearInterval(flashInterval);
33+
document.body.style.backgroundColor = "white";
34+
},
35+
{ once: true }
36+
);
37+
38+
return;
39+
}
40+
41+
// Decrement only if above 0
3442
timeRemaining--;
3543
updateDisplay();
3644
}, 1000);
@@ -46,7 +54,6 @@ function setAlarm() {
4654
}
4755
}
4856

49-
5057
// DO NOT EDIT BELOW HERE
5158

5259
var audio = new Audio("alarmsound.mp3");

0 commit comments

Comments
 (0)