Skip to content

Commit 0a1c10e

Browse files
committed
corrections and improvements after review
1 parent 459b265 commit 0a1c10e

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
let countdown;
2+
3+
// reset before starting new countdown
4+
function resetAlarm() {
5+
clearInterval(countdown);
6+
audio.pause();
7+
document.getElementById("timeRemaining").textContent = "Time Remaining: 00:00";
8+
document.body.classList.toggle("alarm-activated", false);
9+
}
10+
111
function setAlarm() {
212
let seconds = parseInt(document.getElementById("alarmSet").value);
3-
4-
if (seconds <= 0) {
5-
alert("The number of seconds must be more than 0 please");
6-
return;
7-
}
8-
function updateDisplay() {
13+
14+
if (!seconds || seconds < 1) {
15+
alert("The number of seconds must be more than 0 please");
16+
return;
17+
}
18+
function updateDisplay() {
919
const minutes = Math.floor(seconds / 60);
1020
const remainingSeconds = seconds % 60;
1121
document.getElementById("timeRemaining").textContent =
@@ -14,14 +24,20 @@ function setAlarm() {
1424

1525
updateDisplay(); // update immediately on click
1626

17-
const countdown = setInterval(() => {
27+
// code to reset background
28+
function pauseAlarm() {
29+
audio.pause();
30+
document.body.classList.toggle("alarm-activated", false);
31+
}
32+
33+
countdown = setInterval(() => {
1834
seconds--;
1935
updateDisplay();
20-
36+
2137
if (seconds <= 0) {
2238
clearInterval(countdown);
2339
playAlarm();
24-
document.body.style.backgroundColor = "darkorange";
40+
document.body.classList.toggle("alarm-activated", true);
2541
}
2642
}, 1000);
2743
}
@@ -44,9 +60,4 @@ function playAlarm() {
4460
audio.play();
4561
}
4662

47-
function pauseAlarm() {
48-
audio.pause();
49-
document.body.style.backgroundColor = "cornflowerblue";
50-
}
51-
5263
window.onload = setup;

Sprint-3/alarmclock/style.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
left: 50%;
55
-webkit-transform: translate(-50%, -50%);
66
transform: translate(-50%, -50%);
7+
.alarm-activated {
8+
background-color: darkorange;
79
}
810

911
#alarmSet {

0 commit comments

Comments
 (0)