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
32 changes: 31 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
function setAlarm() {}
const input = document.querySelector("#alarmSet");
let timeRemainingEl = document.querySelector("#timeRemaining");
function setAlarm() {
if (!input.value) {
alert("Enter minutes");
return;
}
givenTime = Number(input.value);
updateTime();
clearInterval(timerId);
timerId = setInterval(() => {
givenTime = givenTime - 1;
updateTime();
if (givenTime <= 0) {
clearInterval(timerId);
playAlarm();
return;
}
}, 1000);
}
let timerId;
let givenTime;
function formatTime(givenTime) {
let seconds = givenTime % 60;
let minutes = Math.floor(givenTime / 60);
return `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
}

function updateTime() {
timeRemainingEl.textContent = `Time Remaining: ${formatTime(givenTime)}`;
}

// DO NOT EDIT BELOW HERE

Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/alarmclock.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
*/

require("@testing-library/jest-dom");
const path = require("path");
const { JSDOM } = require("jsdom");

Expand Down
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 App</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" max="60" required placeholder="Enter minutes" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
Expand Down
5 changes: 4 additions & 1 deletion Sprint-3/alarmclock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"bugs": {
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"devDependencies": {
"@testing-library/jest-dom": "^6.9.1"
}
}
6 changes: 5 additions & 1 deletion Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
}

#alarmSet {
margin: 20px;
margin: 15px;
width: 150px;
padding: 2px;
font-size: 16px;
border-radius: 5px;
}

h1 {
Expand Down
Loading