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
35 changes: 33 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
function setAlarm() {}
let myInterval;
function setAlarm() {
clearInterval(myInterval);
pauseAlarm();
const userInput = document.querySelector("#alarmSet").value;
let timeRemaining = Number(userInput);
if (
isNaN(timeRemaining) ||
timeRemaining <= 0 ||
!Number.isInteger(timeRemaining)
Comment on lines +8 to +10

@cjyuan cjyuan Aug 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could probably remove one of these checks as it is redundant.

) {
alert("Please enter a valid whole number.");
return;
}
Comment on lines +5 to +14

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some input values that can make your app behave abnormally can still pass this check. Can you strengthen the check?

updateDisplay(timeRemaining);

// DO NOT EDIT BELOW HERE
myInterval = setInterval(() => {
timeRemaining -= 1;
updateDisplay(timeRemaining);
if (timeRemaining === 0) {
playAlarm();
clearInterval(myInterval);
}
}, 1000);
Comment thread
Abduhasen marked this conversation as resolved.
}

function updateDisplay(timeRemaining) {
const minutes = Math.floor(timeRemaining / 60);
const seconds = timeRemaining % 60;
const formattedMinutes = String(minutes).padStart(2, "0");
const formattedSeconds = String(seconds).padStart(2, "0");
const heading = document.querySelector("#timeRemaining");
heading.innerText = `Time Remaining:${formattedMinutes}:${formattedSeconds}`;
}

var audio = new Audio("alarmsound.mp3");

Expand Down
4 changes: 2 additions & 2 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<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 app</title>
</head>
<body>
<div class="centre">
Expand Down
Loading