Skip to content

Commit 0344ab4

Browse files
committed
JS functionality for the alarm clock
1 parent b4fe6d4 commit 0344ab4

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1-
function setAlarm() {}
1+
function setAlarm() {
2+
const inputSeconds = document.getElementById("alarmSet");
3+
const displayTimer = document.getElementById("timeRemaining")
4+
5+
let remainingSeconds = Number(inputSeconds.value);
6+
7+
const countDownInterval = setInterval(() => {
8+
if (remainingSeconds < 0) {
9+
clearInterval(countDownInterval);
10+
playAlarm();
11+
inputSeconds.value = '';
12+
document.body.style.backgroundColor = 'lightgreen';
13+
return
14+
}
15+
16+
const minutes = Math.floor(remainingSeconds / 60);
17+
const seconds = remainingSeconds % 60;
18+
19+
displayTimer.innerHTML = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
20+
remainingSeconds -= 1;
21+
}, 1000);
22+
23+
}
224

325
// DO NOT EDIT BELOW HERE
426

0 commit comments

Comments
 (0)