Skip to content

Glasgow | ITP May 25 | Mirabelle Morah | Data Groups | Sprint-3 | Alarm Clock #603

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 5 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
69 changes: 67 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
function setAlarm() {}
// 1. When I put a number into the alarmInput field
// 2. Then when I click on "set alarm"
// 3. the number inside the alarm input field should be the same as the numbers next to "Time Remaining:"

// DO NOT EDIT BELOW HERE
let interval = null;
let currentTime = 0;

function setAlarm() {
// Stop any running alarm and reset background before starting a new one
pauseAlarm();
document.body.style.backgroundColor = ""; // reset background

// Get seconds from input field
const alarmInputElement = document.getElementById("alarmSet");
const alarmInput = alarmInputElement.value;
alarmInputElement.value = "";

// This turns the string into a number.
currentTime = parseInt(alarmInput, 10);

// Check if input is not a number or less than or equal to 0
if (isNaN(currentTime) || currentTime <= 0) {
document.getElementById("timeRemaining").innerText =
"Time Remaining: 00:00";
return;
}
Comment on lines +22 to +26

Choose a reason for hiding this comment

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

I would also consider resetting the input to be empty. This way you can let the user know that an action has indeed happened, but it did not resolve into any meaningful result as the input was not valid.

Copy link
Author

Choose a reason for hiding this comment

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

I have put this into consideration and actioned.


updateTime();

// Clear any existing interval
if (interval) {
clearInterval(interval);
}

interval = setInterval(() => {
if (currentTime > 0) {
currentTime--;
updateTime();
}

if (currentTime === 0) {
playAlarm();
document.body.style.backgroundColor = "#db1b3e66";
clearInterval(interval);
}
}, 1000);
}

function updateTime() {
const minutes = String(Math.floor(currentTime / 60)).padStart(2, "0");
const seconds = String(currentTime % 60).padStart(2, "0");
document.getElementById(
"timeRemaining"
).innerText = `Time Remaining: ${minutes}:${seconds}`;
}

// // DO NOT EDIT BELOW HERE

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

Expand All @@ -20,6 +74,17 @@ function playAlarm() {

function pauseAlarm() {
audio.pause();
document.body.style.backgroundColor = ""; // reset background
}

window.onload = setup;

//ignoring the below because the path for this are set in testPathIgnorePatterns (in the package.json or so) and the test.js file states not to edit the tests in alarmclock.test.js

// module.exports = {
// testEnvironment: "jsdom",
// setAlarm,
// pauseAlarm,
// updateTime,
// playAlarm,
// };
12 changes: 10 additions & 2 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
<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">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<label for="alarmSet">Set time to:</label>
<br />

<label for="alarmSet" id="setTime">Set time to:</label>
<br />

<input id="alarmSet" type="number" />
<br />

<button id="set" type="button">Set Alarm</button>

<button id="stop" type="button">Stop Alarm</button>
</div>

<script src="alarmclock.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/user-event": "^13.5.0",
"jest": "^29.2.2",
"jest-environment-jsdom": "^29.2.2"
"jest-environment-jsdom": "^30.0.4"
},
"jest": {
"setupFilesAfterEnv": [
Expand Down
64 changes: 61 additions & 3 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,73 @@
body {
background-color: #f0f0f0;
font-family: "Arial", sans-serif;
padding: 0;
font-family: rubik, sans-serif;
margin: 10px 0;
}

.centre {
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
display: inline-block;
text-align: center;
}

h1 {
text-align: center;
font-size: clamp(1rem, 4vw, 5rem);
}

#setTime {
font-size: clamp(1rem, 2vw, 2rem);
margin: 10px;
display: inline-block;
color: #1b58dbc2;
}

#alarmSet {
margin: 20px;
margin: 20px 40px;
padding: 20px;
max-width: 400px;
height: 100px;
font-size: clamp(1rem, 2vw, 2rem);
box-shadow: #1b58db66 10px 10px;
border-radius: 3px;
border: 0.3px solid rgba(2, 6, 15, 0.4);
transition: all cubic-bezier(0.165, 0.84, 0.44, 1) 0.9s;
}

h1 {
text-align: center;
#alarmSet:hover {
box-shadow: #042b7ec4 20px 20px;
transform: translate(-10px, -10px);
}

#alarmSet:focus {
outline: none;
box-shadow: rgba(29, 30, 37, 0.871) 20px 20px;
transform: translate(-10px, -10px);
}

button {
background-color: #1b58db66;
border: none;
color: white;
padding: 15px 32px;
display: inline-block;
font-size: clamp(1rem, 2vw, 2rem);
margin-top: 60px;
margin-left: 20px;
margin-right: 20px;
cursor: pointer;
box-shadow: rgba(0, 0, 0, 0.114) 10px 10px;
border-radius: 3px;
transition: all cubic-bezier(0.165, 0.84, 0.44, 1) 0.9s;
}

button:hover {
box-shadow: #042b7ec4 20px 20px;
transform: translate(-10px, -10px);
}
Loading