Skip to content
Closed
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
49 changes: 48 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
function setAlarm() {}
let countdownInterval
let alarmTimeout;

function setAlarm() {
const secondsInput = document.getElementById("alarmSet").value;
const totalSeconds = parseInt(secondsInput, 10);

if (isNaN(totalSeconds) || totalSeconds <= 0) {
alert("Please enter a valid number of seconds.");
return;
}

// Clear any existing countdown
clearInterval(countdownInterval);
clearTimeout(alarmTimeout);

const alarmDuration = totalSeconds * 1000;
const endTime = Date.now() + alarmDuration;

// set alarm
alarmTimeout = setTimeout(() => {
playAlarm();
}, alarmDuration);

// Update countdown
const updateCountdown = () => {
const timeLeft = endTime - Date.now();
Comment on lines +26 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is still inconsistently indented compared to the rest of the file


if (timeLeft <= 0) {
clearInterval(countdownInterval);
document.getElementById("timeRemaining").innerText = "Time Remaining: 00:00";
return;
}

const minutes = Math.floor((timeLeft / 1000) / 60);
const seconds = Math.floor((timeLeft / 1000) % 60);

document.getElementById("timeRemaining").innerText =
`Time Remaining: ${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
};

//start countdown
updateCountdown();
countdownInterval = setInterval(updateCountdown, 1000);
}



// DO NOT EDIT BELOW HERE

Expand All @@ -23,3 +69,4 @@ function pauseAlarm() {
}

window.onload = setup;

4 changes: 2 additions & 2 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<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">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />
<input id="alarmSet" type="number" min= "1" placeholder="Second" required />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This input field looks good for normal people, how would a screen reader identify what to input, can this be improved for screen readers?


<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
Expand Down