Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bc8ae20
Created file mean.js & test file mean.test.js and wrote code and test…
EL1VAS Nov 6, 2025
5c7adf7
Created files for exercises and their tests. Copied the code.
EL1VAS Nov 6, 2025
c27dca3
Copied the code in exercise-2 file
EL1VAS Nov 6, 2025
d67bad2
Defined the variable as an array
EL1VAS Nov 6, 2025
b610439
Made numbers the parameter
EL1VAS Nov 6, 2025
67bc3d1
Tried to log the doubleAllNumbers (and failed)
EL1VAS Nov 6, 2025
98a84fc
Created a variable that i could log in the console
EL1VAS Nov 6, 2025
0d09f79
Wrote the function to swap first-last digits of array
EL1VAS Nov 6, 2025
4a38ce9
Deleted the arr[] as testing indicated it was already declared
EL1VAS Nov 6, 2025
9862fc6
Copied file from week 9 preparation and fixed identation
EL1VAS Nov 19, 2025
59febf4
created the script file and added const textarea to access th etextar…
EL1VAS Nov 19, 2025
3fe577a
Added remaining characters const
EL1VAS Nov 19, 2025
df46041
Added an inner text access
EL1VAS Nov 19, 2025
1952aae
Changed the content of character limit info text
EL1VAS Nov 19, 2025
d26af00
Removed text from p as it is given in the javascript file
EL1VAS Nov 19, 2025
13043fc
Added the keyup and addEventListener
EL1VAS Nov 19, 2025
0af1764
Coppied the new code
EL1VAS Nov 19, 2025
2da3276
Fixed typo and used the function before we declare it
EL1VAS Nov 19, 2025
9f2588e
changed title element to Alarm clock app
EL1VAS Nov 20, 2025
30f68c3
Changed the tittle element to be Alarm clock app
EL1VAS Nov 20, 2025
d0f0d0b
Changed Set time to with set time to (in seconds) and added a comment
EL1VAS Nov 20, 2025
8f38b20
Accesing the value of the input
EL1VAS Nov 20, 2025
fdb7fc3
Wrote a function to format the input (seconds) to minutes and seconds
EL1VAS Nov 20, 2025
a7d6697
Added padding to display of minutes and seconds
EL1VAS Nov 20, 2025
a2b3848
Corrected Math.round to Math.floor
EL1VAS Nov 20, 2025
def100d
Forgot to return the function, fixed it
EL1VAS Nov 20, 2025
e936672
Added the inner text message to show the formated input
EL1VAS Nov 20, 2025
be570ab
Created the interval function to create a countdown every second that…
EL1VAS Nov 20, 2025
46db839
Added the alarm play function
EL1VAS Nov 20, 2025
64e2539
Added packages needed for the test file to run
EL1VAS Nov 20, 2025
d501fd1
Tried to add background color
EL1VAS Nov 20, 2025
3a3a6e5
I know I shouldn't alter that part of code, but I needed the color to…
EL1VAS Nov 20, 2025
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
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"tabWidth": 4,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false
Expand Down
47 changes: 38 additions & 9 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
function setAlarm() {}
function formatTime(totalSeconds) {
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
const mm = String(minutes).padStart(2, "0"); // Added padding to cover the chance the input is a single number
const ss = String(seconds).padStart(2, "0"); // Also I wanted to match the format of the Time remaining

return `${mm}:${ss}`;
}

function setAlarm() {
const inputValue = document.getElementById("alarmSet").value; // Get the value that we input in the box
const formatedInput = formatTime(inputValue); // Use function above to format the number in the input to mm:ss format
let remainingSeconds = inputValue; // Added after to be used in the interval function
const timeRemaining = document.getElementById("timeRemaining"); // Get to the element of the header Time Remaining
timeRemaining.innerText = `Time Remaining: ${formatedInput}`; // And change its text to display the formated input
const intervalId = setInterval(function () {
// Function that will be repeated every second
remainingSeconds -= 1; // And will deduct a second everytime the function runs
timeRemaining.innerText = `Time Remaining: ${formatTime(
remainingSeconds
)}`; // And will show a countdown display in the header
if (remainingSeconds <= 0) {
// When countdown reaches 00:00
clearInterval(intervalId); // Function will stop running
playAlarm(); // Alarm will start playing on 00:00
document.body.style.backgroundColor = "orange";
}
}, 1000);
}

// DO NOT EDIT BELOW HERE

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

function setup() {
document.getElementById("set").addEventListener("click", () => {
setAlarm();
});
document.getElementById("set").addEventListener("click", () => {
setAlarm();
});

document.getElementById("stop").addEventListener("click", () => {
pauseAlarm();
});
document.getElementById("stop").addEventListener("click", () => {
pauseAlarm();
});
}

function playAlarm() {
audio.play();
audio.play();
}

function pauseAlarm() {
audio.pause();
audio.pause();
document.body.style.backgroundColor = "white"; // Sorry to alter the code, but I had to reset it when paused
}

window.onload = setup;
33 changes: 17 additions & 16 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<!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>
</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" />
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Alarm clock app</title>
</head>
<body>
<div class="centre">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<label for="alarmSet">Set time to (in seconds):</label>
<!--Defined that input number represents seconds-->
<input id="alarmSet" type="number" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="alarmclock.js"></script>
</body>
<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="alarmclock.js"></script>
</body>
</html>
8 changes: 7 additions & 1 deletion Sprint-3/alarmclock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@
"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",
"jest": "^30.2.0",
"jest-environment-jsdom": "^30.2.0",
"jsdom": "^26.1.0"
}
}
14 changes: 14 additions & 0 deletions prep/exercise-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Can you fix this code?
function doubleAllNumbers(numbers) {
let doubledNumbers = [];

for (let n of numbers) {
doubledNumbers.push(n * 2);
}

return doubledNumbers;
}

const myNums = [10, 20, 30];
const double = doubleAllNumbers(myNums);
console.log(double);
Empty file added prep/exercise-1.test.js
Empty file.
13 changes: 13 additions & 0 deletions prep/exercise-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Write a function which takes an array as a parameter
// and swaps the first element with the last element

function swapFirstAndLast(arr) {
const first = arr[0]; //Indivates the first digit location of the array
const last = arr[arr.length - 1]; //Indicates the lst digit location of the array
arr[0] = last; //Because I can't reassign a new value to a const and we want the first position to hold the value of the last
arr[arr.length - 1] = first;
}

const myArray = [5, 2, 3, 4, 1];
swapFirstAndLast(myArray);
console.log(myArray); // what output should we expect?
Empty file added prep/exercise-2.test.js
Empty file.
24 changes: 24 additions & 0 deletions prep/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Alarm clock app</title>
<script defer src="script.js"></script>
</head>
<body>
<section>
<h3>Character limit</h3>
<label for="comment-input">
Please enter your comment in the text area below
</label>
<textarea
id="comment-input"
name="comment-input"
rows="5"
maxlength="200"
></textarea>
<p id="character-limit-info"></p>
</section>
</body>
</html>
20 changes: 20 additions & 0 deletions prep/mean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function calculateMean(list) {
let total = 0;
for (const item of list) {
total += item;
}
}

function calculateMedian(list) {
const middleIndex = Math.floor(list.length / 2);
const median = list.splice(middleIndex, 1)[0];

return median;
}

const list = [10, 20, 30];
const copy = list;
copy.push(60, 70);

console.log(list);
console.log(copy);
6 changes: 6 additions & 0 deletions prep/mean.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test("calculates the median of a list of odd length", () => {
const list = [10, 20, 30, 50, 60];
const currentOutput = calculateMedian(list);
const targetOutput = 30;
expect(currentOutput).toEqual(targetOutput);
});
10 changes: 10 additions & 0 deletions prep/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const textarea = document.querySelector("textarea");
updateCharacterLimit();

function updateCharacterLimit() {
const remainingCharacters = textarea.maxLength - textarea.value.length;
const charactersLeftP = document.querySelector("#character-limit-info");
charactersLeftP.innerText = `You have ${remainingCharacters} characters remaining`;
}

textarea.addEventListener("keyup", updateCharacterLimit);