Skip to content

Commit d36586d

Browse files
Complete feature/sprint-3-alarmclock
1 parent cfd674c commit d36586d

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
function setAlarm() {}
1+
function setScreenTimer(totalSeconds) {
2+
const minutes = Math.floor(totalSeconds / 60);
3+
const seconds = totalSeconds % 60;
4+
const timeRemainingSpan = document.querySelector("#timeRemaining span");
5+
timeRemainingSpan.textContent = `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
6+
}
7+
8+
function setAlarm() {
9+
const alarmSet = document.getElementById("alarmSet");
10+
let totalSeconds = Number(alarmSet.value);
11+
12+
setScreenTimer(totalSeconds);
13+
14+
const timer = setInterval(() => {
15+
totalSeconds--;
16+
if (totalSeconds <= 0) {
17+
setScreenTimer(0);
18+
clearInterval(timer);
19+
playAlarm();
20+
} else {
21+
setScreenTimer(totalSeconds);
22+
}
23+
}, 1000);
24+
}
225

326
// DO NOT EDIT BELOW HERE
427

Sprint-3/alarmclock/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
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">
11-
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
11+
<h1 id="timeRemaining">Time Remaining: <span>00:00</span></h1>
1212
<label for="alarmSet">Set time to:</label>
1313
<input id="alarmSet" type="number" />
1414

1515
<button id="set" type="button">Set Alarm</button>
1616
<button id="stop" type="button">Stop Alarm</button>
1717
</div>
18-
<script src="alarmclock.js"></script>
18+
<script src="alarmclock.js" defer></script>
1919
</body>
2020
</html>

0 commit comments

Comments
 (0)