Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
371ac88
examples prep
ldfajardo10-tech Oct 16, 2025
68d5fc8
key exercises (2-initials solution)
ldfajardo10-tech Oct 27, 2025
43a7404
key exercises (1-count solution)
ldfajardo10-tech Oct 27, 2025
fc4edcc
key exercises (3-paths solution)
ldfajardo10-tech Oct 27, 2025
72bce3d
key exercise (4-random)
ldfajardo10-tech Oct 27, 2025
a4c0b5f
mandatory error exercise solution 1
ldfajardo10-tech Oct 27, 2025
78698fd
mandadtory error exercise solution 2
ldfajardo10-tech Oct 27, 2025
e00363d
exercise 3 solution
ldfajardo10-tech Nov 2, 2025
fd66c25
exercise 4 solution
ldfajardo10-tech Nov 2, 2025
cd25015
1 percentage change exercise solution
ldfajardo10-tech Nov 2, 2025
651f59e
exercise 0 solution mandatory debug
ldfajardo10-tech Nov 12, 2025
a118f95
exercise 1 solution mandatory debug
ldfajardo10-tech Nov 12, 2025
767c156
solution exercise 3 mandatory debug
ldfajardo10-tech Nov 12, 2025
0830b09
exercise 1 solution mandatory-implement
ldfajardo10-tech Nov 13, 2025
23b5e32
exercise 2 solution mandatory implement
ldfajardo10-tech Nov 13, 2025
c648323
exercise 3 solution mandatory-implement
ldfajardo10-tech Nov 13, 2025
0263110
exercise 4 solution mandatory-interpret
ldfajardo10-tech Nov 13, 2025
dc463db
exercise 1 solution implement and rewrite tests
ldfajardo10-tech Nov 18, 2025
8449410
exercise 2 solution implement and write test
ldfajardo10-tech Nov 18, 2025
e4f0ed9
exercise 3-implement solution
ldfajardo10-tech Nov 18, 2025
b2b31c1
exercise 1 solution rewrite test
ldfajardo10-tech Nov 19, 2025
02fd2ca
update
ldfajardo10-tech Nov 20, 2025
7744787
update exercise 2 implement solution
ldfajardo10-tech Nov 20, 2025
349247e
exercise 2 solution rewrite test
ldfajardo10-tech Nov 20, 2025
26bb0c5
update exercise solution 3 implement
ldfajardo10-tech Nov 20, 2025
1afbbbf
exercise 3 solution rewrite test
ldfajardo10-tech 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: 2 additions & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ count = count + 1;

// Line 1 is a variable declaration, creating the count variable with an initial value of 0
// Describe what line 3 is doing, in particular focus on what = is doing

// The line 3 is just incrementing the counting
4 changes: 3 additions & 1 deletion Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ let lastName = "Johnson";
// Declare a variable called initials that stores the first character of each string.
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.

let initials = ``;
let initials = firstName[0] + middleName[0] + lastName[0];

console.log(initials);

// https://www.google.com/search?q=get+first+character+of+string+mdn

9 changes: 7 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
const dir = filePath.slice(0, lastSlashIndex);
const ext = filePath.slice(lastSlashIndex + 5);

console.log(`The base part of ${filePath} is ${base}`);
console.log(`The dir part of ${filePath} is ${dir}`);
console.log(`The ext part of ${filePath} is ${ext}`);


// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable

const dir = ;
const ext = ;


// https://www.google.com/search?q=slice+mdn
4 changes: 3 additions & 1 deletion Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ const minimum = 1;
const maximum = 100;

const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

console.log(num);
// In this exercise, you will need to work out what num represents?
// Try breaking down the expression and using documentation to explain what it means
// It will help to think about the order in which expressions are evaluated
// Try logging the value of num and running the program several times to build an idea of what the program is doing

// represents a whole random number between 1 and 100
6 changes: 5 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
age = age + 1;

// instead of const, we should use let because it means that the variable can change

let age = 33;
age = age + 1;
2 changes: 2 additions & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

// the line console.log can't be before the variable
7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);

console.log(last4Digits);

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
// Before running the code, make and explain a prediction about why the code won't work
// Then run the code and see what error it gives.
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
// Then try updating the expression last4Digits is assigned to, in order to get the correct value

// the .slice is a string method and the number is not a string

6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const TwelveHourClockTime = "20:53";
const twentyFourHourClockTime = "08:53";

// the name of the variable can't start with a number
12 changes: 6 additions & 6 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let carPrice = "10,000";
let priceAfterOneYear = "8,543";
let carPrice = "10,000"; // variable declaration
let priceAfterOneYear = "8,543"; // variable declaration

carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
carPrice = Number(carPrice.replaceAll(",", "")); // variable reassignment statement and function call (.replaceall is replacing the comma for a empty space and the number() is converting the string into a number value)
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // variable reassignment statement and function call

const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
const priceDifference = carPrice - priceAfterOneYear; // variable declaration
const percentageChange = (priceDifference / carPrice) * 100; // variable declaration

console.log(`The percentage change is ${percentageChange}`);

Expand Down
8 changes: 7 additions & 1 deletion Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Predict and explain first...

// =============> write your prediction here
// =============> instead of console log should be return

function multiply(a, b) {
console.log(a * b);
Expand All @@ -12,3 +12,9 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// Finally, correct the code to fix the problem
// =============> write your new code here

function multiply(a, b) {
return (a * b);
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10 changes: 8 additions & 2 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Predict and explain first...
// =============> write your prediction here
// =============> return shouldn't be separated by (;)

function sum(a, b) {
return;
Expand All @@ -8,6 +8,12 @@ function sum(a, b) {

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
// =============> semicolon ends the statement so it wouldn't return anything
// Finally, correct the code to fix the problem
// =============> write your new code here

function sum(a, b) {
return a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
21 changes: 16 additions & 5 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here

// =============> the slice index can't be negative
const num = 103;

function getLastDigit() {
Expand All @@ -14,11 +13,23 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`);

// Now run the code and compare the output to your prediction
// =============> write the output here
// =============>
// The last digit of 42 is 3
//The last digit of 105 is 3
//The last digit of 806 is 3
// Explain why the output is the way it is
// =============> write your explanation here
// =============> the constant was declared out of the function
// Finally, correct the code to fix the problem
// =============> write your new code here
// =============>


function getLastDigit(num) {
return num.toString().slice(-1);
}

console.log(`The last digit of 42 is ${getLastDigit(42)}`);
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`);

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
13 changes: 10 additions & 3 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
// Then when we call this function with the weight and height
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
const height = 1.70;
const weight = 55;

function calculateBMI(height, weight) {
const squaredHeight = height * height;
const result = weight / squaredHeight;
return result;
}

console.log(`the Daniela's BMI is ${calculateBMI(height, weight)}`);
7 changes: 7 additions & 0 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@
// You will need to come up with an appropriate name for the function
// Use the MDN string documentation to help you find a solution
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase


const sentence = "hello\tworld";

const result = sentence.replace("\t", "_").toUpperCase();

console.log(result);
25 changes: 25 additions & 0 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,28 @@
// You will need to declare a function called toPounds with an appropriately named parameter.

// You should call this function a number of times to check it works for different inputs

function toPounds(penceString) {
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(
3,
"0"
);
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

return `£${pounds}.${pence}`;
}

console.log(toPounds("399p"));
console.log(toPounds("585p"));
13 changes: 8 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ function formatTimeDisplay(seconds) {
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
}


console.log(formatTimeDisplay(61));

// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
// to help you answer these questions

// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> 3

// Call formatTimeDisplay with an input of 61, now answer the following:

// b) What is the value assigned to num when pad is called for the first time?
// =============> write your answer here
// =============> 0, because totalHours is 0

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> 00

// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
// =============> 1, because 60 is one minute and the remaining second would be 1 (61)

// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
// =============> 01, because the remaining seconds are padded 2 index
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
function getAngleType(angle) {
if (angle === 90) {
return "Right angle";
}
if (angle < 90) {
return "Acute angle";
}
if (angle > 90 && angle < 180) {
return "Obtuse angle";
}
if ( angle === 180) {
return "Straight angle"
}
if ( angle > 180 && angle < 360) {
return "Reflex angle"
}
// Run the tests, work out what Case 2 is testing, and implement the required code here.
// Then keep going for the other cases, one at a time.
}

// The line below allows us to load the getAngleType function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getAngleType;

// we're going to use this helper function to make our assertions easier to read
// if the actual output matches the target output, the test will pass
function assertEquals(actualOutput, targetOutput) {
Expand All @@ -33,10 +38,11 @@ function assertEquals(actualOutput, targetOutput) {
// Given an angle in degrees,
// When the function getAngleType is called with this angle,
// Then it should:

module.exports = getAngleType;
// Case 1: Identify Right Angles:
// When the angle is exactly 90 degrees,
// Then the function should return "Right angle"

const right = getAngleType(90);
assertEquals(right, "Right angle");

Expand All @@ -50,14 +56,21 @@ assertEquals(acute, "Acute angle");
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(obtuse, "Obtuse angle");

// ====> // ====> write your test here, and then add a line to pass the test in the function above

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
// ====> write your test here, and then add a line to pass the test in the function above
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");

// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
// ====> write your test here, and then add a line to pass the test in the function above
// ====> write your test here, and then add a line to pass the test in the function above

const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ function isProperFraction(numerator, denominator) {
if (numerator < denominator) {
return true;
}
if (numerator > denominator) {
return false;
}
if (numerator === denominator) {
return false;
}
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand Down Expand Up @@ -46,14 +52,14 @@ assertEquals(improperFraction, false);
// target output: true
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
const negativeFraction = isProperFraction(-4, 7);
// ====> complete with your assertion
assertEquals(properFraction, true);

// Equal Numerator and Denominator check:
// Input: numerator = 3, denominator = 3
// target output: false
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
const equalFraction = isProperFraction(3, 3);
// ====> complete with your assertion
assertEquals(equalFraction, false);

// Stretch:
// What other scenarios could you test for?
Loading