Skip to content

Commit 76cb8e7

Browse files
author
Enice-Codes
committed
completed the alarm requirements
1 parent de6889c commit 76cb8e7

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1-
function setAlarm() {}
1+
let timer = null;
22

3-
// DO NOT EDIT BELOW HERE
3+
function formatTime(totalSeconds) {
4+
const minutes = Math.floor(totalSeconds / 60);
5+
const seconds = totalSeconds % 60;
6+
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
7+
}
8+
9+
function updateDisplay(seconds) {
10+
document.getElementById("timeRemaining").textContent =
11+
`Time Remaining: ${formatTime(seconds)}`;
12+
}
13+
14+
function setAlarm() {
15+
if (timer) {
16+
clearInterval(timer);
17+
}
418

19+
let seconds = Number(document.getElementById("alarmSet").value);
20+
updateDisplay(seconds);
21+
22+
timer = setInterval(() => {
23+
seconds--;
24+
updateDisplay(seconds);
25+
26+
if (seconds <= 0) {
27+
clearInterval(timer);
28+
playAlarm();
29+
}
30+
}, 1000);
31+
}
32+
33+
// DO NOT EDIT BELOW HERE
534
var audio = new Audio("alarmsound.mp3");
635

736
function setup() {
@@ -22,4 +51,4 @@ function pauseAlarm() {
2251
audio.pause();
2352
}
2453

25-
window.onload = setup;
54+
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)