Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
function setAlarm() {}
let alarmInterval;

function setAlarm() {
Comment thread
LonMcGregor marked this conversation as resolved.
//change the time remaining and set the remaining time
//into the second.
clearInterval(alarmInterval);

const InputField = document.getElementById("alarmSet");
let timeRemaining = Number(InputField.value);

if (!InputField.value || InputField.value < 0) {
alert("Please enter a valid time in seconds");
return;
}

function updateDisplay() {
const timeDisplay = document.getElementById("timeRemaining");
const Minute = Math.floor(timeRemaining / 60);
const Second = timeRemaining % 60;

const formatMinute = String(Minute).padStart(2, "0");
const formatSecond = String(Second).padStart(2, "0");

timeDisplay.innerText = `Time Remaining: ${formatMinute}:${formatSecond}`;
}

updateDisplay();
Comment thread
LonMcGregor marked this conversation as resolved.
//set a variable to count three actions:
// count -1;
// Show what is the remaining time;
// if it goes to zero, beep the sound and stop the counting
alarmInterval = setInterval(() => {
Comment thread
LonMcGregor marked this conversation as resolved.
timeRemaining = timeRemaining - 1;

updateDisplay();

if (timeRemaining === 0) {
playAlarm();
clearInterval(alarmInterval);
}
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand All @@ -19,7 +60,8 @@ function playAlarm() {
}

function pauseAlarm() {
clearInterval(alarmInterval);
audio.pause();
}

window.onload = setup;
window.onload = setup;
1 change: 1 addition & 0 deletions Sprint-3/alarmclock/alarmclock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test("should set heading when button is clicked", () => {
button.click();

expect(heading).toHaveTextContent("Time Remaining: 00:19");

});

test("should split values over 60 seconds into minutes and seconds", () => {
Expand Down
4 changes: 2 additions & 2 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Title here</title>
<title>Alarm Clock</title>
</head>
<body>
<div class="centre">
Expand All @@ -17,4 +17,4 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>
</div>
<script src="alarmclock.js"></script>
</body>
</html>
</html>
Loading