Skip to content

Commit b235bd1

Browse files
committed
Implement alarm functionality and update title in HTML
1 parent 3d4c407 commit b235bd1

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
1-
function setAlarm() {}
1+
let intervalId;
2+
3+
function setAlarm() {
4+
const input = document.getElementById("alarmSet");
5+
let time = Number(input.value);
6+
7+
const heading = document.getElementById("timeRemaining");
8+
9+
clearInterval(intervalId);
10+
11+
function format(num) {
12+
if (num < 10) return "0" + num;
13+
return num;
14+
}
15+
16+
heading.innerText =
17+
"Time Remaining: " +
18+
format(Math.floor(time / 60)) +
19+
":" +
20+
format(time % 60);
21+
22+
intervalId = setInterval(() => {
23+
time--;
24+
25+
if (time <= 0) {
26+
heading.innerText = "Time Remaining: 00:00";
27+
clearInterval(intervalId);
28+
playAlarm();
29+
return;
30+
}
31+
32+
heading.innerText =
33+
"Time Remaining: " +
34+
format(Math.floor(time / 60)) +
35+
":" +
36+
format(time % 60);
37+
}, 1000);
38+
}
239

340
// DO NOT EDIT BELOW HERE
441

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/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@testing-library/dom": "^10.4.0",
2727
"@testing-library/jest-dom": "^6.6.3",
2828
"@testing-library/user-event": "^14.6.1",
29-
"jest": "^30.0.4",
29+
"jest": "^30.2.0",
3030
"jest-environment-jsdom": "^30.0.4"
3131
}
3232
}

0 commit comments

Comments
 (0)