Skip to content

Commit 63c3803

Browse files
committed
Complete Alarm Clock App
1 parent 96d077b commit 63c3803

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

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+
let countdownInterval;
2+
3+
function setAlarm() {
4+
const inputElement = document.getElementById("alarmSet");
5+
const timeDisplay = document.getElementById("timeRemaining");
6+
7+
let timeRemaining = parseInt(inputElement.value, 10) || 0;
8+
9+
clearInterval(countdownInterval);
10+
11+
function updateDisplay() {
12+
const minutes = String(Math.floor(timeRemaining / 60)).padStart(2, "0");
13+
const seconds = String(timeRemaining % 60).padStart(2, "0");
14+
timeDisplay.innerText = `Time Remaining: ${minutes}:${seconds}`;
15+
}
16+
17+
updateDisplay();
18+
19+
countdownInterval = setInterval(() => {
20+
timeRemaining--;
21+
22+
if (timeRemaining < 0) {
23+
clearInterval(countdownInterval);
24+
playAlarm();
25+
} else {
26+
updateDisplay();
27+
}
28+
}, 1000);
29+
}
230

331
// DO NOT EDIT BELOW HERE
432

Sprint-3/alarmclock/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
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">
1111
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
1212
<label for="alarmSet">Set time to:</label>
13-
<input id="alarmSet" type="number" />
13+
<input id="alarmSet" type="number" min="0" />
1414

1515
<button id="set" type="button">Set Alarm</button>
1616
<button id="stop" type="button">Stop Alarm</button>

0 commit comments

Comments
 (0)