Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
087f40a
Fix capitalise() function by removing variable name conflict and addi…
SlimMicheals Dec 17, 2025
da683b9
Fix convertToPercentage function and add prediction + explanation
SlimMicheals Dec 17, 2025
3f5720c
Fix square() error and add prediction + explanation
SlimMicheals Dec 17, 2025
07fec8d
Fix multiply function by adding return statement and explain why unde…
SlimMicheals Dec 17, 2025
57cca82
Fix sum() function and add prediction + explanation
SlimMicheals Dec 17, 2025
5c92fab
Fix getLastDigit function and add prediction + output + explanation
SlimMicheals Dec 17, 2025
116919e
Implement calculateBMI function to return BMI to 1 decimal place
SlimMicheals Dec 17, 2025
695b166
Implement toUpperSnakeCase() function to convert strings to UPPER_SNA…
SlimMicheals Dec 17, 2025
23e34fc
Add detailed step-by-step explanation for to-pounds program
SlimMicheals Dec 18, 2025
e3315e3
Fix syntax error in to-pounds implementation
SlimMicheals Dec 18, 2025
c5e2c83
Answer time-format interpret questions
SlimMicheals Dec 18, 2025
ecf10d9
Add edge case tests for midnight and noon
SlimMicheals Dec 18, 2025
e681012
Implement getAngleType to handle all angle cases
SlimMicheals Dec 22, 2025
696ae3f
Implement isProperFraction and complete acceptance tests
SlimMicheals Dec 22, 2025
e337427
Complete getCardValue implementation with tests for numbers, face car…
SlimMicheals Dec 22, 2025
a4a2853
Implement getCardValue with tests for numbers, face cards, ace, and i…
SlimMicheals Dec 22, 2025
1af18bd
Implement getAngleType and set up Jest
SlimMicheals Dec 22, 2025
3e65e97
Implement getAngleType with full angle classification
SlimMicheals Dec 22, 2025
5495298
Implement getAngleType with full test coverage
SlimMicheals Dec 22, 2025
db418fb
Implement isProperFraction logic
SlimMicheals Dec 22, 2025
a859959
Complete isProperFraction implementation and tests
SlimMicheals Dec 22, 2025
4947eaa
Fix require path and complete isProperFraction tests
SlimMicheals Dec 22, 2025
f20212b
Implement getCardValue with numeric, face card, ace, and invalid hand…
SlimMicheals Dec 22, 2025
38fc236
Implement getCardValue with full test coverage
SlimMicheals Dec 23, 2025
7546720
Add card number validation logic for stretch investigate task
SlimMicheals Dec 25, 2025
02d174b
Add explanations for while loop behavior in find function
SlimMicheals Dec 25, 2025
1370f04
Verify password validator passes initial length test
SlimMicheals Dec 25, 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
33 changes: 29 additions & 4 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,35 @@
// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring

function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
//function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
//return str;
//}

// =============> write your explanation here
// =============> write your new code here

// Prediction:
// I think this code will not work because the function uses the name "str" twice.
// The parameter is already called str, but inside the function we write "let str = ...",
// which tries to create a new variable with the same name.
// JavaScript does not allow this, so I expect an error about "str" already being declared.
// To fix it, I will probably need to use a different variable name inside the function.

function capitalise(str) {
let firstLetter = str[0].toUpperCase();
let restOfWord = str.slice(1);
return firstLetter + restOfWord;
}

console.log(capitalise("hello"));
console.log(capitalise("javascript"));

// Explanation:
// When the code runs, JavaScript shows an error saying that "str" has already been declared.
// This happens because the function parameter is named "str", and inside the function we also
// try to declare another variable with the same name using "let str = ...".
// JavaScript does not allow a variable to be redeclared in the same scope.
// To fix the problem, i replaced the inner "str" variable with two new variables:
// one for the first letter and one for the rest of the word.
// This removes the name conflict and the function works correctly.
42 changes: 36 additions & 6 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,48 @@
// Why will an error occur when this program runs?
// =============> write your prediction here

// Prediction:
// I think this code will cause an error when it runs.
// The function parameter is named "decimalNumber", but inside the function
// we try to declare another variable also called "decimalNumber" using
// "const decimalNumber = 0.5".
// JavaScript does not allow redeclaring a constant with the same name
// inside the same scope, so it will throw an error.
// I expect a "Identifier 'decimalNumber' has already been declared" error.


// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;
//function convertToPercentage(decimalNumber) {
// const decimalNumber = 0.5;
//const percentage = `${decimalNumber * 100}%`;

return percentage;
}
//return percentage;
//}

console.log(decimalNumber);
//console.log(decimalNumber);

// =============> write your explanation here

// Explanation:
// The error happens because "decimalNumber" is used twice.
// First, it is the function parameter (convertToPercentage(decimalNumber)).
// Then inside the function we try to declare another constant with the same
// name using "const decimalNumber = 0.5".
// JavaScript does not allow a constant to be redeclared inside the same scope,
// so it throws an error saying the name has already been declared.
// To fix it, we must remove the inner const or use a different variable name.


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

// Fixed function
function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;
return percentage;
}

console.log(convertToPercentage(0.5));
console.log(convertToPercentage(0.25));

34 changes: 31 additions & 3 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,44 @@

// =============> write your prediction of the error here

function square(3) {
return num * num;
}
// Prediction:
// I think this code will cause an error because the function parameter is written as (3)
// Instead of naming the parameter (like num), we are writing a number in the function definition.
// JavaScript expects a VARIABLE name inside the parentheses, not a value.
// Because of this, I expect a syntax error before the code even runs.


//function square(3) {
//return num * num;
//}

// =============> write the error message here

// Error message:
// SyntaxError: Unexpected number


// =============> explain this error message here

// Explanation:
// The error happens because the function is written as square(3).
// In a function definition, the part inside the parentheses must be a parameter name,
// like (num), (value), or (x). It cannot be an actual number.
// JavaScript sees the number 3 where it expects a variable name,
// so it throws a “Unexpected number” syntax error.


// Finally, correct the code to fix the problem

// =============> write your new code here

// Fixed function
function square(num) {
return num * num;
}

console.log(square(3));
console.log(square(5));



26 changes: 22 additions & 4 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@

// =============> write your prediction here

function multiply(a, b) {
console.log(a * b);
}
// I think this code will not work correctly because the function multiply()
// prints the result using console.log(a * b) but it does not return anything.
// When we call multiply(10, 32) inside a template string, JavaScript expects
// the function to return a value.
// Because there is no return statement, the function will return "undefined".
// So I expect the final output to print the correct multiplication once,
// and then show "undefined" in the sentence.

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

//function multiply(a, b) {
//console.log(a * b);
//}

//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here

// The function multiply() prints the result using console.log() but does not return it.
// When we call multiply(10, 32) inside the template string, JavaScript expects a value,
// but the function returns undefined. That's why the output says "undefined".


// 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)}`);
32 changes: 27 additions & 5 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
// Predict and explain first...
// =============> write your prediction here

function sum(a, b) {
return;
a + b;
}
// I think this code will not work correctly because the function sum()
// has a return statement with nothing after it.
// When JavaScript sees return; it immediately stops the function
// and returns undefined.
// The line a + b will never run, so the result will be undefined.
// Therefore, the output will say: "The sum of 10 and 32 is undefined".

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

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

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

// =============> write your explanation here

// The problem happens because the function uses return; on the first line.
// When JavaScript hits a return statement, it immediately leaves the function.
// That means a + b is never executed.
// A function with an empty return always returns undefined.
// To fix this, we must return the value of a + b.

// 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)}`);

59 changes: 52 additions & 7 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,67 @@
// Predict the output of the following code:
// =============> Write your prediction here

const num = 103;
// I think the code will NOT work correctly.
// The function getLastDigit() is supposed to take a number (like 42 or 105)
// but the function is defined with NO PARAMETERS.
//
// Inside the function, it always uses "num", which is the constant 103 at the top.
// So no matter what number we pass into getLastDigit(...), the function will ALWAYS
// return the last digit of 103 - which is "3".
//
// So I predict that all three console.log() lines will print:
// "The last digit of 42 is 3"
// "The last digit of 105 is 3"
// "The last digit of 806 is 3"

function getLastDigit() {
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)}`);
//const num = 103;

//function getLastDigit() {
//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)}`);

// 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

// getLastDigit is defined with no parameters: function getLastDigit() {...}
// But when we call it, we pass numbers: getLastDigit(42), getLastDigit(105), etc.
// The function ignores those numbers because it never receives them.
//
// Inside the function, it always uses the variable "num",
// which is a constant with the value 103 at the top of the file.
//
// That means getLastDigit() always returns the last digit of 103,
// which is "3", no matter what number we pass in.

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

// Fixed function
function getLastDigit(n) {
return n.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

// I changed getLastDigit() so it accepts a parameter "n".
// Now each time we call getLastDigit(42), the value 42 is received as "n".
// Then n.toString().slice(-1) correctly returns the last digit of that number.
// This removes the dependency on the global num variable.
9 changes: 8 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
}

//Fix
function calculateBMI(weight, height) {
const heightSquared = height * height;
const bmi = weight / heightSquared;
return Number(bmi.toFixed(1));
}
8 changes: 8 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,11 @@
// 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


function toUpperSnakeCase(str) {
const withUnderscores = str.replace(/ /g, "_");
const result = withUnderscores.toUpperCase();
return result;
}

30 changes: 30 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,33 @@
// 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


const penceString = "399p";

// This creates a string that represents a price in pence.
// The "p" at the end means pence.

const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);
// This removes the last character (“p”) so we are left only with the numbers, e.g. "399".

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
// This ensures the number always has at least 3 digits by adding zeros at the front if needed.
// Example: "5" becomes "005". This helps keep the formatting consistent.

const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
// This takes all digits except the last two.
// Those digits represent the pounds portion.

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
// This takes the last two digits, which represent the pence value.
// padEnd makes sure it is always exactly two digits.

console.log(`${pounds}.${pence}`);
// This prints the price in pounds format, like “3.99”.

11 changes: 6 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ function formatTimeDisplay(seconds) {
// Questions

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

// 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
// num 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
// num is 1 because remainingSeconds is 1 when seconds = 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 pad adds a leading zero to make two digits

11 changes: 11 additions & 0 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

console.assert(
formatAs12HourClock("00:00") === "12:00 am",
"midnight case failed"
);

console.assert(
formatAs12HourClock("12:00") === "12:00 pm",
"noon case failed"
);

Loading