From 754dd3ad4ef1d9f781cb808536ba767c8cff7be0 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Mon, 29 Jun 2026 15:29:38 +0100 Subject: [PATCH 01/15] my predicted code --- Sprint-2/1-key-errors/0.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..a7e211df46 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,30 @@ // Predict and explain first... -// =============> write your prediction here +// If you try to run this code, it will throw a SyntaxError: Identifier 'str' has already been declared. // 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; + let str = `${str[0].toUpperCase()}${str.slice(1)}`; + + return str; } +// When you define function capitalise(str), JavaScript automatically creates a local variable named str inside the function's scope, +// assigning it whatever value you pass into the function. +// The let keyword has a strict rule: you cannot declare a variable that already exists in the same scope. +// Because str was already claimed by the function's parameter, JavaScript immediately stops and throws a SyntaxError before it even tries to capitalize anything. +// this is the reason why the error is occurring. +// the if condition i added is to ensure that if an empty string is passed to the function, it will return the empty string instead of throwing an error. +// To fix the error, you can simply remove the let keyword and just assign the new value to str without redeclaring it. + +function capitalise(str) { + if (typeof str !== "string") { + return str; + } + + return `${str[0].toUpperCase()}${str.slice(1)}`; + +} +console.log(capitalise("hello world!")); + -// =============> write your explanation here -// =============> write your new code here From 78515601cb57bae4da05d237977440deda2cc32a Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Mon, 29 Jun 2026 16:04:51 +0100 Subject: [PATCH 02/15] my correct code for percentage conversion --- Sprint-2/1-key-errors/1.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..fda7177dae 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,7 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// this will throw a SyntaxError: Identifier 'decimalNumber' has already been declared. // Try playing computer with the example to work out what is going on @@ -14,7 +14,17 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// it will throw this error SyntaxError: Identifier 'decimalNumber' has already been declared. +// by declaring the variable decimalNumber as a parameter inside the function parentheses. +// This will create it again on the next line using const, JavaScript gets confused and blocks the code from running. // Finally, correct the code to fix the problem -// =============> write your new code here +// this is the correct code below + +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(0.5)); From af9f6d78ed07d6828cf50f0e56adeba110cf25f9 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Mon, 29 Jun 2026 17:21:48 +0100 Subject: [PATCH 03/15] correcting and predicting code. my correction --- Sprint-2/1-key-errors/2.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..d0ea4b08ed 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,21 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// Variable and parameter names must be identifiers (like words, e.g., num, x, myNumber). +//They cannot be literal values or specific numbers like 3. function square(3) { return num * num; } -// =============> write the error message here +// the error message is: SyntaxError: Unexpected number. -// =============> explain this error message here +// The error message SyntaxError: Unexpected number means that JavaScript encountered a raw number, +// where it was strictly expecting to see a variable name. // Finally, correct the code to fix the problem - // =============> write your new code here - - +function square(num) { + return num * num; +} +console.log(square(3)); From 4c6b444b23e1e2367ddaf0e1ab3d798d3e631b34 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Mon, 29 Jun 2026 19:42:52 +0100 Subject: [PATCH 04/15] correcting error message for square num --- Sprint-2/1-key-errors/2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index d0ea4b08ed..80ce302c71 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -6,9 +6,9 @@ // Variable and parameter names must be identifiers (like words, e.g., num, x, myNumber). //They cannot be literal values or specific numbers like 3. -function square(3) { - return num * num; -} +//function square(3) { + //return num * num; +//} // the error message is: SyntaxError: Unexpected number. From 3ba86a11d39959563cd052e5da60d8c054324de6 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Mon, 29 Jun 2026 19:43:45 +0100 Subject: [PATCH 05/15] correction for multiplication function --- Sprint-2/2-mandatory-debug/0.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..6646d18ab2 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,7 @@ // Predict and explain first... -// =============> write your prediction here +// This code will actually run without throwing a red crash error, +// but it will print something very strange. the result of multiplying 10 and 32 is undefined. function multiply(a, b) { console.log(a * b); @@ -8,7 +9,14 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// console.log() inside the function: Inside the multiply function, you used console.log(a * b). +// This instantly prints 320 to the screen, but it does not give that number back to the code that called it. +//The Missing return: In JavaScript, if a function does not explicitly use the word return, it automatically hands back undefined. +//The undefined string: Because multiply(10, 32) returns undefined, your outer console.log plugs undefined into the sentence, resulting in: "The result of multiplying 10 and 32 is undefined". -// Finally, correct the code to fix the problem -// =============> write your new code here +// Finally, correct the code to fix the problem +function multiply(a, b) { + return a * b; +} + +console.log(multiply(10, 32)); \ No newline at end of file From 66591aac300eb592c8c16f3576ede2233cbb04eb Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Mon, 29 Jun 2026 19:44:27 +0100 Subject: [PATCH 06/15] correction for square function --- Sprint-2/1-key-errors/2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 80ce302c71..5c7d30a9c3 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -6,9 +6,9 @@ // Variable and parameter names must be identifiers (like words, e.g., num, x, myNumber). //They cannot be literal values or specific numbers like 3. -//function square(3) { +function square(3) { //return num * num; -//} +} // the error message is: SyntaxError: Unexpected number. From e01a422321b512116c340515c872feb90d83eed0 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Mon, 29 Jun 2026 20:01:19 +0100 Subject: [PATCH 07/15] correcting the sum function --- Sprint-2/2-mandatory-debug/1.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..ddaeac9d68 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,7 @@ // Predict and explain first... -// =============> write your prediction here +// This code will run without throwing a crash error, but it will print an incorrect result. +// The output will be:This code will run without throwing a crash error, but it will print an incorrect result. +// The output will be: The sum of 10 and 32 is undefined function sum(a, b) { return; @@ -8,6 +10,13 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> the explanation: +// The function sum has a return statement before the addition operation, which causes the function to return undefined immediately. +// To fix this, the return statement should be placed after the addition operation. +// because the function is not a string i have to remove the backticks and use a normal string concatenation to print the result correctly. // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; +} +console.log(sum(10, 32)); From 8b5f715145955a2b996266c9fc3c157598753bd9 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 30 Jun 2026 11:58:05 +0100 Subject: [PATCH 08/15] new correction to the code --- Sprint-2/2-mandatory-debug/2.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..671957f04e 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,11 +1,12 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// this code might not run properly because the function getLastDigit is not set up to take any parameters, +// but we are trying to pass in a number when we call it. -const num = 103; +//const num = 103; -function getLastDigit() { +function getLastDigit(num) { return num.toString().slice(-1); } @@ -14,11 +15,29 @@ 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 output is the way it is because the function getLastDigit does not take any parameters, +// but we are trying to pass in a number when we call it. Instead, the function is using the variable num which is set to 103. +// Therefore, regardless of what number we pass in, the function will always return the last digit of 103, which is 3. + // Finally, correct the code to fix the problem -// =============> write your new code here + +const num = 103; + +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 +// The function getLastDigit is not working properly because it does not take any parameters, +// to fix the problem, we need to add a parameter to the function definition so that it can accept a number when called. \ No newline at end of file From 0520f97f5a6002cfd0e840eda483c59dc38d5075 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 30 Jun 2026 13:27:44 +0100 Subject: [PATCH 09/15] code to return to decimal function --- Sprint-2/3-mandatory-implement/1-bmi.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..3e9596bf92 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,7 @@ // 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 -} \ No newline at end of file + const bmi = weight / (height * height); + return bmi.toFixed(1); +} +console.log(calculateBMI(70, 1.73)); \ No newline at end of file From d548b1d155ed288abfde0a1f735fadb9f93a5331 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 30 Jun 2026 14:26:37 +0100 Subject: [PATCH 10/15] my code for uppercase --- Sprint-2/3-mandatory-implement/2-cases.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..4f19f46a6f 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,8 @@ // 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) { + return str.toUpperCase().replace(/ /g, '_'); +} +console.log(toUpperSnakeCase("lord of the rings")); \ No newline at end of file From 5208285e8f0b7a8e4382902046d7a41a9076e532 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 30 Jun 2026 16:18:54 +0100 Subject: [PATCH 11/15] my reusable code for pounds --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..4d13137b39 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,27 @@ // 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("1250p")); +console.log(toPounds("5p")); +console.log(toPounds("70p")); +console.log(toPounds("0p")); \ No newline at end of file From ba8e5408d46c445a7a7d19b28efb89a8a1a6ffce Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Wed, 1 Jul 2026 10:39:42 +0100 Subject: [PATCH 12/15] my explanation to the code --- Sprint-2/4-mandatory-interpret/time-format.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..eee7583219 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -21,18 +21,25 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// pad will be called 3 times. Inside the return statement of formatTimeDisplay, +// pad is called once for totalHours, once for remainingMinutes, and once for remainingSeconds. // 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 +// Answer: 0. Reason: The first evaluation in the template literal is pad(totalHours). +// Since totalHours is 0, 0 is passed as the argument to num. // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// answer: "00". Reason: The while loop in pad checks if the length of numString is less than 2. +// Since numString is "0", the loop runs and adds a "0" to the front, making it "00". +// The loop then checks again, and since the length is now 2, it exits and returns "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 +// Answer: 1. Reason: The last evaluation in the template literal is pad(remainingSeconds). +// Since remainingSeconds is 1, 1 is passed as the argument to num. // 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". Reason: The while loop in pad checks if the length of numString is less than 2. +// Since numString is "1", the loop runs and adds a "0" to the front, making it "01". +// The loop then checks again, and since the length is now 2, it exits and returns "01". From 32e9c0265a5e4dfc8ddcc8761ceecf2df714ef7f Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Thu, 2 Jul 2026 09:37:51 +0100 Subject: [PATCH 13/15] my code to fix the bug --- Sprint-2/5-stretch-extend/format-time.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b8..e8fd75e65d 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,12 +4,20 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); + if (hours > 12) { - return `${hours - 12}:00 pm`; + const convertedHours = hours - 12; + // Pad the hour with a leading zero if it's a single digit (e.g., 3 becomes "03") + const paddedHours = String(convertedHours).padStart(2, "0"); + return `${paddedHours}:${minutes} pm`; } + return `${time} am`; } +// === Your Tests (All will now pass silently!) === + const currentOutput = formatAs12HourClock("08:00"); const targetOutput = "08:00 am"; console.assert( @@ -23,3 +31,11 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +console.assert(formatAs12HourClock("15:00") === "03:00 pm", `Failed Case D: 03:00 pm`); +console.assert(formatAs12HourClock("13:00") === "01:00 pm", `Failed Case E: 01:00 pm`); +console.assert(formatAs12HourClock("15:45") === "03:45 pm", `Failed Case D: 03:45 pm`); +console.assert(formatAs12HourClock("13:45") === "01:45 pm", `Failed Case E: 01:45 pm`); +console.assert(formatAs12HourClock("08:45") === "08:45 am", `Failed Case F: 08:45 am`); + +console.log("All current assertions completed!"); \ No newline at end of file From 443e1ecfd8c926aa720d3b2696f82794519058e1 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Thu, 2 Jul 2026 10:37:08 +0100 Subject: [PATCH 14/15] new --- str | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 str diff --git a/str b/str new file mode 100644 index 0000000000..1d9110dd3d --- /dev/null +++ b/str @@ -0,0 +1,5 @@ +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; + +} +console.log(capitalise("hello world!")); From 261e7d9e794ede1cd1516da0b1caba0893635f5c Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Thu, 2 Jul 2026 10:44:40 +0100 Subject: [PATCH 15/15] re moval of the new --- str | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 str diff --git a/str b/str deleted file mode 100644 index 1d9110dd3d..0000000000 --- a/str +++ /dev/null @@ -1,5 +0,0 @@ -function capitalise(str) { - return `${str[0].toUpperCase()}${str.slice(1)}`; - -} -console.log(capitalise("hello world!"));