Skip to content

Commit f93276d

Browse files
committed
implement an alarm function and update title in index.html
1 parent aa7da66 commit f93276d

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1-
function setAlarm() {}
1+
function setAlarm() {
2+
let time = Number(document.getElementById("alarmSet").value);
3+
const heading = document.getElementById("timeRemaining");
4+
5+
audio.loop = true;
6+
7+
document.body.style.backgroundColor = "";
8+
9+
function updateDisplay(t) {
10+
const minutes = String(Math.floor(t / 60)).padStart(2, "0");
11+
const seconds = String(t % 60).padStart(2, "0");
12+
heading.innerText = `Time Remaining: ${minutes}:${seconds}`;
13+
}
14+
15+
updateDisplay(time);
16+
17+
const intervalId = setInterval(() => {
18+
time--;
19+
20+
if (time <= 0) {
21+
clearInterval(intervalId);
22+
updateDisplay(0);
23+
24+
document.body.style.backgroundColor = "red";
25+
26+
playAlarm();
27+
28+
} else {
29+
updateDisplay(time);
30+
}
31+
}, 1000);
32+
}
33+
234

335
// DO NOT EDIT BELOW HERE
436

@@ -22,4 +54,4 @@ function pauseAlarm() {
2254
audio.pause();
2355
}
2456

25-
window.onload = setup;
57+
window.onload = setup;

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">

0 commit comments

Comments
 (0)