Skip to content

Commit 229a2de

Browse files
committed
update the page title and write alarmclock code
1 parent cbcdcc9 commit 229a2de

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
1-
function setAlarm() {}
1+
let timerId = null;
2+
let remainingSeconds = 0;
3+
4+
function updateDisplay() {
5+
let minutes = String(Math.floor(remainingSeconds / 60)).padStart(2, "0");
6+
let seconds = String(remainingSeconds % 60).padStart(2, "0");
7+
document.getElementById(
8+
"timeRemaining"
9+
).textContent = `Time Remaining: ${minutes}:${seconds}`;
10+
}
11+
12+
function startCountdown() {
13+
timerId = setInterval(() => {
14+
remainingSeconds -= 1;
15+
updateDisplay();
16+
if (remainingSeconds === 0) {
17+
remainingSeconds = 0;
18+
clearInterval(timerId);
19+
timerId = null;
20+
playAlarm();
21+
}
22+
}, 1000);
23+
}
24+
25+
function setAlarm() {
26+
const input = document.getElementById("alarmSet");
27+
const inputValue = Number(input.value);
28+
clearInterval(timerId);
29+
timerId = null;
30+
remainingSeconds = inputValue;
31+
32+
updateDisplay();
33+
startCountdown();
34+
}
235

336
// DO NOT EDIT BELOW HERE
437

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)