Skip to content

Sheffield|May-2025|Sheida Shabankari|Module-Data -Groups| Sprint-3|Alarm Clock #631

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 15 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
45 changes: 44 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
function setAlarm() {}
let flashColor, secondsInterval;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since they both hold interval ID, can you keep the naming convention consistent?

Note: When I first saw the name flashColor, I cannot figure out the purpose of the variable.


function setAlarm() {
const userInput = document.getElementById("alarmSet");

const inputTime = parseInt(userInput.value);
if (inputTime <= 0 || isNaN(inputTime)) {
alert("invalid input!!!");
return;
}

clearInterval(secondsInterval);
clearInterval(flashColor);
pauseAlarm();
let remainingTime = inputTime;
updateDisplayTime(remainingTime);

secondsInterval = setInterval(() => {
remainingTime--;
updateDisplayTime(remainingTime);
if (remainingTime === 0) {
clearInterval(secondsInterval);
playAlarm();
}
}, 1000);
}

function updateDisplayTime(inputTime) {
const timeRemain = document.getElementById("timeRemaining");
const min = String(Math.floor(inputTime / 60)).padStart(2, "0");
const sec = String(inputTime % 60).padStart(2, "0");
timeRemain.textContent = `Time Remaining: ${min}:${sec}`;
}
// DO NOT EDIT BELOW HERE

var audio = new Audio("alarmsound.mp3");
Expand All @@ -16,10 +47,22 @@ function setup() {

function playAlarm() {
audio.play();
document.getElementById("stop").style.backgroundColor = "rgb(191, 115, 47)";
document.body.style.backgroundColor = "rgb(218, 178, 119)";
flashColor = setInterval(() => {
if (document.body.style.backgroundColor === "rgb(218, 178, 119)") {
document.body.style.backgroundColor = "white";
} else {
document.body.style.backgroundColor = "rgb(218, 178, 119)";
}
}, 500);
}

function pauseAlarm() {
audio.pause();
document.getElementById("stop").style.backgroundColor = "rgb(239, 239, 239)";
clearInterval(flashColor);
document.body.style.backgroundColor = "white";
}

window.onload = setup;
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
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"devDependencies": {
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/user-event": "^13.5.0",
"jest": "^29.2.2",
"jest-environment-jsdom": "^29.2.2"
Expand Down
Loading