Skip to content

Glasgow | ITP May 2025 | Adiyah Farhan | Sprint 3 | Alarm Clock #741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
48 changes: 47 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
function setAlarm() {}
let countdownInterval; // Variable to hold the countdown interval

function setAlarm() {
if (countdownInterval) {
clearInterval(countdownInterval);
}
// Get the input value from the alarm input field
let inputNum = document.getElementById("alarmSet");
let alarmTime = Number(inputNum.value);

// reset the background color to white
document.body.style.backgroundColor = "white";

// Update the time remaining display
updateTimeRemaining(alarmTime);

//Setting the interval so that when one second passes, the time remaining will be updated
countdownInterval = setInterval(() => {
alarmTime--;

if (alarmTime <= 0) {
clearInterval(countdownInterval);
updateTimeRemaining(0);
document.body.style.backgroundColor = "red";
playAlarm();
return;
} else {
updateTimeRemaining(alarmTime);
}
}, 1000);
}

function updateTimeRemaining(seconds) {
// Converting the input value into a time format
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
const formattedTime = `${mins.toString().padStart(2, "0")}:${secs
.toString()
.padStart(2, "0")}`;

// Set the alarm time in the Time Remaining display
document.getElementById("timeRemaining").innerText =
"Time Remaining: " + formattedTime;
}

// DO NOT EDIT BELOW HERE

Expand All @@ -11,6 +54,9 @@ function setup() {

document.getElementById("stop").addEventListener("click", () => {
pauseAlarm();
//Reset the background color to white when the alarm is stopped
document.body.style.backgroundColor = "white";
document.getElementById("alarmSet").value = "";
});
}

Expand Down
2 changes: 1 addition & 1 deletion 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 App</title>
</head>
<body>
<div class="centre">
Expand Down