Skip to content

Commit 3c5b7b9

Browse files
committed
Complete alarm clock countdown and flashing background
1 parent 03c6296 commit 3c5b7b9

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
1-
function setAlarm() {}
1+
function setAlarm() {
2+
const input = document.getElementById("alarmSet");
3+
const heading = document.getElementById("timeRemaining");
4+
5+
let remainingSeconds = Number(input.value);
6+
7+
function formatTime(totalSeconds) {
8+
const minutes = Math.floor(totalSeconds / 60);
9+
const seconds = totalSeconds % 60;
10+
11+
const mm = String(minutes).padStart(2, "0");
12+
const ss = String(seconds).padStart(2, "0");
13+
14+
return `${mm}:${ss}`;
15+
}
16+
17+
heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;
18+
19+
const intervalId = setInterval(() => {
20+
remainingSeconds -= 1;
21+
22+
if (remainingSeconds > 0) {
23+
heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;
24+
} else {
25+
heading.innerText = "Time Remaining: 00:00";
26+
clearInterval(intervalId);
27+
playAlarm();
28+
document.body.classList.add("flash");
29+
}
30+
}, 1000);
31+
}
32+
33+
function stopFlashingBackground() {
34+
document.body.classList.remove("flash");
35+
}
236

337
// DO NOT EDIT BELOW HERE
438

‎Sprint-3/alarmclock/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<link rel="stylesheet" href="style.css" />
7-
<title>Title here</title>
7+
<title>Alarm clock app</title>
88
</head>
99
<body>
1010
<div class="centre">

‎Sprint-3/alarmclock/style.css‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@
1313
h1 {
1414
text-align: center;
1515
}
16+
17+
.flash {
18+
animation: flash-bg 0.5s infinite alternate;
19+
}
20+
21+
@keyframes flash-bg {
22+
from { background-color: white; }
23+
to { background-color: red; }
24+
}
25+

0 commit comments

Comments
 (0)