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
704f58f
added a comment explaining the role of the = .
TTiamiyu Jun 13, 2026
dc17501
Implemented the function to get the initials as output without writin…
TTiamiyu Jun 13, 2026
dce53b5
Add dir and ext variable assignments in 3-paths.js
TTiamiyu Jun 13, 2026
cecb6ba
added a "for" statement, for random number generation to log multiple…
TTiamiyu Jun 15, 2026
bbfef51
Added comments to explain code execution prevention and commenting me…
TTiamiyu Jun 15, 2026
274fe16
Change age variable declaration from const to let for reassignment
TTiamiyu Jun 15, 2026
63265cb
Fix console log placement to correctly print city of birth
TTiamiyu Jun 15, 2026
e6db536
Fix card number assignment to string for correct slicing of last 4 di…
TTiamiyu Jun 15, 2026
1c5023d
Fix variable naming for twelve and twenty-four hour clock time
TTiamiyu Jun 16, 2026
b06aae3
Add comments to clarify function calls, variable assignments, and err…
TTiamiyu Jun 16, 2026
496d1b8
Enhance comments for clarity on variable declarations, function calls…
TTiamiyu Jun 16, 2026
32d7119
Enhance comments to provide a detailed step-by-step explanation of th…
TTiamiyu Jun 16, 2026
5e06e8c
Add results section to document outcomes of alert and prompt function…
TTiamiyu Jun 16, 2026
7503415
Add outputs and answers for console exploration activity
TTiamiyu Jun 16, 2026
abb3aa5
Clarify prediction comment regarding potential error due to variable …
TTiamiyu Jun 22, 2026
9bf321e
Fix variable redeclaration error in capitalise function and update ex…
TTiamiyu Jun 22, 2026
0642903
Fix syntax errors in convertToPercentage and square functions, and up…
TTiamiyu Jun 24, 2026
aaa500c
Add predictions and explanations for multiply and sum functions, and …
TTiamiyu Jun 24, 2026
0c1f1ad
Fix formatting in explanation comment for sum function
TTiamiyu Jun 24, 2026
231d91e
Fix getLastDigit function to accept parameters and update predictions…
TTiamiyu Jun 26, 2026
17c3829
Implement BMI calculation function and add example usage
TTiamiyu Jun 26, 2026
99dad40
Implement upperSnakeCase function to convert strings to UPPER_SNAKE_C…
TTiamiyu Jun 26, 2026
3fee2c5
Implement toPounds function to convert pence to formatted pounds and …
TTiamiyu Jun 26, 2026
80f3a4f
Update comments in formatTimeDisplay function to provide detailed exp…
TTiamiyu Jun 26, 2026
7d4c0fb
Refactor formatAs12HourClock function to improve time formatting logi…
TTiamiyu Jun 29, 2026
f7edaf1
Fix typo in explanation comment for pad function return value
TTiamiyu Jun 30, 2026
2cae221
Revert Sprint-1 files to base code
TTiamiyu Jul 3, 2026
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
9 changes: 7 additions & 2 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Predict and explain first...
// =============> write your prediction here
// =============> An error is likely to occur due to repeat of "str"

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
Expand All @@ -9,5 +9,10 @@ function capitalise(str) {
return str;
}

// =============> write your explanation here
// =============> SyntaxError: Identifier 'str' has already been declared. This error occurs because the variable 'str' is being declared again within the function,
// which is not allowed. To fix this, we can simply remove the 'let' declaration.
// =============> write your new code here
function capitalise(str) {
return `${str[0].toUpperCase()}${str.slice(1)}`;
}
console.log(capitalise("brother"));
17 changes: 15 additions & 2 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@
// Why will an error occur when this program runs?
// =============> write your prediction here

//Prediction: The program will fail with a SyntaxError because 'decimalNumber' is redeclared.

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

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
//const decimalNumber = 0.5; <--- this line causes the syntaxError.
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(decimalNumber);
//console.log(decimalNumber); <--- this line causes the ReferenceError.

// =============> write your explanation here
//1. Inside the function: Just like the previous example, the parameter `decimalNumber` acts as a local variable. Trying to redeclare it with `const decimalNumber = 0.5;` causes a crash.
// Additionally, hardcoding 0.5 defeats the purpose of having a parameter at all.

// 2. Outside the function: The variable `decimalNumber` is "scoped" to the function. It doesn't exist in the outside world. When `console.log(decimalNumber)` runs globally, JavaScript doesn't know what it is,
// causing a ReferenceError. You need to call the function and pass the number as an argument instead.

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

function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;
return percentage;
}
console.log(convertToPercentage(0.5));
9 changes: 7 additions & 2 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
// this function should square any number but instead we're going to get an error

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

// Prediction: The code would likely return a syntax error because the parameter in the () is '3' and not 'num'.
function square(3) {
return num * num;
}

// =============> write the error message here
// SyntaxError: Unexpected number

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

// A defined function in a () must be variable names, not values.
// Finally, correct the code to fix the problem

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


function square(num) {
return num * num;
}
console.log(square(3));
10 changes: 10 additions & 0 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Predict and explain first...

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

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

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

/*Explanation: The `multiply` function calculates `a * b` and immediately prints it to
the console, but it doesn't use the `return` keyword to hand the value back.

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

//The sum would return as undefined.

function sum(a, b) {
return;
a + b;
Expand All @@ -9,5 +11,15 @@ function sum(a, b) {
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

// Explanation: The return keyword is used and the functions is not executed because the expression is on a different line
//which means the computer would not run the expression alongside the return keyword.

// 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: 21 additions & 0 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// Predict the output of the following code:
// =============> Write your prediction here
//I predict the code will output the number '3' for every function call.

const num = 103;

Expand All @@ -15,10 +16,30 @@ 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

//OUTPUT: '3' was the output for every function call, which is not what I predicted.

// Explain why the output is the way it is
// =============> write your explanation here

// The output is the way it is because the first line of the code a const statement was declared with the value of 103,
// and the function getLastDigit() is using that constant instead of the argument passed.

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

// This function did not work because javascript looks for the variable inside it and as it was not declared in the function '()' it went looking for num in the global code
// and locked onto the declared constant value of num = 103 instead of running the passed arguments individually.
// the code as been corrected by removing the const num = 103 and added num as a parameter to the function getLastDigit(num) so it can now take the arguments individually and return the right output.
6 changes: 6 additions & 0 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
const bmi = weight / (height * height);
return Math.round(bmi * 10) / 10;
}

console.log(calculateBMI(90, 1.85)); // should return 26.3

// return the BMI of someone based off their weight and height
}
10 changes: 10 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,13 @@
// 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 NAME: upperSnakeCase

function upperSnakeCase(string) {
const upperCaseString = string.toUpperCase();
return upperCaseString.replace(' ', '_');
}

console.log(upperSnakeCase("ultimate team")); // should return "ULTIMATE_TEAM"
console.log(upperSnakeCase(("grand theft auto VI")); // should return "GRAND_THEFT_AUTO_VI"
33 changes: 33 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,36 @@
// 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) {
// 1. Remove the trailing 'p'
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);

// 2. Pad with zeros to ensure we always have at least 3 digits (e.g., "5" becomes "005")
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");

// 3. Extract the pounds (everything except the last two digits)
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);

// 4. Extract the pence (just the last two digits)
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

// 5. Return the formatted currency string
return `£${pounds}.${pence}`;
}

// --- Test Cases ---
// Calling the function multiple times to check it works for different inputs
console.log(toPounds("399p")); // Expected output: "£3.99"
console.log(toPounds("5p")); // Expected output: "£0.05"
console.log(toPounds("2500p")); // Expected output: "£25.00"
console.log(toPounds("99p")); // Expected output: "£0.99"
console.log(toPounds("10000p")); // Expected output: "£100.00"
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 @@ -21,18 +21,21 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> It would be called 3 times, that is for hours, minutes and seconds.

// 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
// =============> The answer would be '0' because the first time pad is called, relates to the hours remaining.

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> It would return '00' because the value of num 0 is converted to a string "0", since its length is less than two the pad function adds a "0" to the front to output "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
// =============> The answer is 1.
//explanation: the last time pad is called is for the remaining seconds, which would return 1 because we passed 61 into the program, calculated as 61 % 60.

// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
// =============> write your answer here
// =============> Answer "01".
// Explanation: The return value of pad when it is called for the last time in this program is '01'. This is because the value of num is 1 (the remaining seconds after calculating 61 % 60).
// Since the length of the string representation of 1 is less than 2, the pad function adds a "0" to the front, resulting in "01".
34 changes: 31 additions & 3 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@

function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
const minutes = time.slice(3, 5);
if (hours >= 12) {
const pmHours = String(hours === 12 ? 12 : hours - 12).padStart(2, "0");
return `${pmHours}:${minutes} pm`;
}
const amHours = String(hours === 0 ? 12 : hours).padStart(2, "0");
return `${amHours}:${minutes} am`;
}

function runTest(description, input, expected) {
const result = formatAs12HourClock(input);
console.assert(
result === expected,
`Test failed for ${description}: expected ${expected}, got ${result}`
);
if (result === expected) {
console.log(`Test passed for ${description}`);
}
return `${time} am`;
}

const currentOutput = formatAs12HourClock("08:00");
Expand All @@ -23,3 +37,17 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

//== Additional Test Cases =//

// Test case for standard AM time
runTest("Standard early morning", "08:00", "08:00 am");
runTest("standard late morning", "11:30", "11:30 am");

// Test case for standard PM time
runTest("Standard afternoon", "13:15", "01:15 pm");
runTest("Standard evening", "20:45", "08:45 pm");

// Test case for 12-hour threshold2
runTest("Exact Noon (12:00)", "12:00", "12:00 pm");
runTest("Exact Midnight", "00:00", "12:00 am");
Loading