Skip to content

Commit 97289e8

Browse files
author
Pretty Taruvinga
committed
Implement alarm countdown functionality
1 parent 53fa90f commit 97289e8

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
function setAlarm() {}
1+
function setAlarm() {
2+
const input = document.getElementById("alarmSet").value;
3+
const heading = document.getElementById("timeRemaining");
4+
5+
let totalSeconds = Number(input);
6+
7+
function updateDisplay(seconds) {
8+
const min = Math.floor(seconds / 60);
9+
const secs = seconds % 60;
10+
11+
const formattedMin = String(min).padStart(2, "0");
12+
const formattedSecs = String(secs).padStart(2, "0");
13+
14+
heading.innerText = `Time Remaining: ${formattedMin}:${formattedSecs}`;
15+
}
16+
updateDisplay(totalSeconds);
17+
18+
const timer = setInterval(() => {
19+
totalSeconds--;
20+
21+
if (totalSeconds <= 0) {
22+
updateDisplay(0);
23+
clearInterval(timer);
24+
playAlarm();
25+
} else {
26+
updateDisplay(totalSeconds);
27+
}
28+
}, 1000);
29+
}
230

331
// DO NOT EDIT BELOW HERE
432

Sprint-3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
"@testing-library/jest-dom": "^6.6.3",
2828
"@testing-library/user-event": "^14.6.1",
2929
"jest": "^30.0.4",
30-
"jest-environment-jsdom": "^30.0.4"
30+
"jest-environment-jsdom": "^30.3.0"
3131
}
3232
}

0 commit comments

Comments
 (0)