Skip to content

Commit c26fd30

Browse files
author
Arthur
committed
alarm clock final commit
1 parent 4222cda commit c26fd30

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
1-
function setAlarm() {}
1+
function setAlarm() {
2+
//change the time remaining and set the remaining time
3+
//into the second.
4+
5+
let alarmInterval;
6+
const InputField = document.querySelector("#alarmSet");
7+
let timeRemaining = InputField.value;
8+
9+
function updateDisplay() {
10+
const timedisplay = document.querySelector("#timeRemaining");
11+
const Minute = Math.floor(timeRemaining / 60);
12+
const Second = timeRemaining % 60;
13+
14+
const formatMinute = String(Minute).padStart(2, "0");
15+
const formatSecond = String(Second).padStart(2, "0");
16+
17+
timedisplay.innerText = `Time Remaining: ${formatMinute}:${formatSecond}`;
18+
}
19+
20+
updateDisplay();
21+
//set a variable to count three actions:
22+
// count -1;
23+
// Show what is the remaining time;
24+
// if it goes to zero, beep the sound and stop the counting
25+
26+
alarmInterval = setInterval(() => {
27+
timeRemaining = timeRemaining - 1;
28+
29+
updateDisplay();
30+
31+
if (timeRemaining === 0) {
32+
playAlarm();
33+
clearInterval(alarmInterval);
34+
}
35+
}, 1000);
36+
}
237

338
// DO NOT EDIT BELOW HERE
439

@@ -20,6 +55,8 @@ function playAlarm() {
2055

2156
function pauseAlarm() {
2257
audio.pause();
58+
59+
clearInterval(alarmInterval);
2360
}
2461

2562
window.onload = setup;

Sprint-3/alarmclock/alarmclock.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ test("should set heading when button is clicked", () => {
4444
button.click();
4545

4646
expect(heading).toHaveTextContent("Time Remaining: 00:19");
47+
4748
});
4849

4950
test("should split values over 60 seconds into minutes and seconds", () => {

Sprint-3/alarmclock/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>
1818
<script src="alarmclock.js"></script>
1919
</body>
2020
</html>
21+
22+
23+
24+
25+
26+

0 commit comments

Comments
 (0)