From 9f9df24b8f3ae73297ed4aae4881f6180b475b3f Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 12 Feb 2026 23:01:44 +0000 Subject: [PATCH 01/18] Increasing the variable count by 1 --- Sprint-1/1-key-exercises/1-count.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..0a339bdac6 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,8 @@ let count = 0; count = count + 1; +/* The line 3 is increasing the variable count by 1 and assigning the result to count variable on the left hand * side. + */ + // 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 From dd440df95eb37a4a607c3dacbc60b65439143f54 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Fri, 13 Feb 2026 00:14:56 +0000 Subject: [PATCH 02/18] Added 2-initials.js file --- .gitignore | 5 ++++- Sprint-1/1-key-exercises/2-initials.js | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bde36e5302..2ff82044a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ node_modules .DS_Store .vscode -**/.DS_Store \ No newline at end of file +**/.DS_Store +.gitignore +.git + diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..73d5c29757 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,8 @@ 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 From ac3104fd3e645fb126a6b56be87d1d3f94f6b866 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 16 Feb 2026 23:56:08 +0000 Subject: [PATCH 03/18] 0.js file committed --- Sprint-2/1-key-errors/0.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..5da9eeb2ee 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,41 @@ // Predict and explain first... // =============> write your prediction here +/** Prediction: + * The code will throw an error because the parameter str and the variable str inside the function are both declared in the same scope. + * +*/ + // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +/** Original function: + * function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } +*/ // =============> write your explanation here +/** Explanation: + * The error occurs because: + * + * The function parameter str is already declared in the function scope + * Inside the function, we're trying to redeclare str using let which creates a new variable in the same scope + * JavaScript doesn't allow redeclaring a variable with let in the same scope + * The error message would be something like: + * SyntaxError: Identifier 'str' has already been declared +*/ + // =============> write your new code here + +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} + +// Test the function +console.log(capitalise("hello")); // "Hello" +console.log(capitalise("world")); // "World" + From 46081abd33e89d82d23c493e1b0221683dbea3fe Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 16 Feb 2026 23:56:24 +0000 Subject: [PATCH 04/18] 1.js file committed --- Sprint-2/1-key-errors/1.js | 42 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..729b0774f5 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,48 @@ // Predict and explain first... // Why will an error occur when this program runs? + // =============> write your prediction here +/** + * Prediction: + * An error will occur because the function parameter decimalNumber is being redeclared inside the function body using const. This creates a naming conflict - you can't have a parameter and a local variable with the same name. + * Additionally, the console.log(decimalNumber) at the end will cause a ReferenceError because decimalNumber is not defined in the global scope - it's only defined within the function's scope. + */ // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +/** + * Explanation + * The code has two main problems: + * Redeclaration error: The function parameter decimalNumber is being redeclared with const decimalNumber = 0.5 inside the function. In JavaScript, you cannot have a variable with the same name as a parameter in the same scope. + * Scope error: The console.log(decimalNumber) at the end is trying to access a variable that only exists inside the function's scope. Variables declared inside functions are not accessible from the outside. + * Logic error: Even if the scope issues were fixed, the function always returns "50%" regardless of the input because it overwrites the parameter with 0.5. + */ - return percentage; -} - -console.log(decimalNumber); +/** Original function: + * + * function convertToPercentage(decimalNumber) { + * const decimalNumber = 0.5; + * const percentage = `${decimalNumber * 100}%`; + * + * return percentage; + * } + * + * console.log(decimalNumber); + */ // =============> write your explanation here // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; +} + +// Example usage: +const decimalNumber = 0.5; +console.log(convertToPercentage(decimalNumber)); // Output: "50%" +console.log(convertToPercentage(0.80)); // Output: "80%" + From 7f678f9da5412c3b679f166f65088d019b678f3d Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Mon, 16 Feb 2026 23:56:43 +0000 Subject: [PATCH 05/18] 2.js file committed --- Sprint-2/1-key-errors/2.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..c4d6bafc44 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,41 @@ // Predict and explain first BEFORE you run any code... - // this function should square any number but instead we're going to get an error - // =============> write your prediction of the error here -function square(3) { - return num * num; -} +/** + * Prediction: + * The function parameter is incorrectly defined as a numeric literal 3 instead of a parameter name. This will cause a syntax error because JavaScript function parameters must be valid identifiers (variable names), not numbers. + */ + +/** Original function: + * + * function square(3) { + * return num * num; + * } + */ + // =============> write the error message here +/** + * Error message: + * Uncaught SyntaxError: Unexpected number + */ // =============> explain this error message here +/** Explanation: + * In JavaScript, when defining a function, the parameters must be valid variable names (like num, x, value, etc.). Using a literal number like 3 as a parameter is invalid syntax because: + * Parameters act as placeholders for values that will be passed when the function is called + * Numbers can not be used as variable names in JavaScript + * The parser expects a valid identifier in the parameter declaration, not a numeric literal + */ // Finally, correct the code to fix the problem - // =============> write your new code here +function square(num) { + return num * num; +} + +console.log(square(3)); From 5e85fd2de548fe79da342e191e11a6cbdfa696d3 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 19 Feb 2026 23:43:35 +0000 Subject: [PATCH 06/18] 0.js committed --- Sprint-2/2-mandatory-debug/0.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..8393b40c5e 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,33 @@ // Predict and explain first... // =============> write your prediction here +/** + * It display "320" and "The result of multiplying 10 and 32 is undefined" + */ +/** 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 +/** Explanation: + * + * The following function takes two arguments as input and display the multiplication result. + * But instead of using the function "console.log" it shoudl use the function "return (a * b)". + * That's the reason it displays "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)}`); + From 39b4b88448828f4976592c30fd416776f1d64f16 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 19 Feb 2026 23:44:00 +0000 Subject: [PATCH 07/18] 1.js committed --- Sprint-2/2-mandatory-debug/1.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..bbb4554a5e 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,25 @@ // Predict and explain first... // =============> write your prediction here +/** + * It returns an "undefined" + */ -function sum(a, b) { +/** function sum(a, b) { return; a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +*/ // =============> write your explanation here + /** The arguments "a + b" should be on the same line as the return so the sum returns that value instead of "undefined" + */ + // 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)}`); From 74142a1ff876a98f92f41afba99d60fccbc56490 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 19 Feb 2026 23:44:16 +0000 Subject: [PATCH 08/18] 2.js committed --- Sprint-2/2-mandatory-debug/2.js | 61 +++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..4ae3c7f00f 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -3,22 +3,69 @@ // Predict the output of the following code: // =============> Write your prediction here -const num = 103; +/** + * The last digit of 42 input is '3' + * The last digit of 105 input is '3' + * The last digit of 806 input is '3' + */ -function getLastDigit() { - return num.toString().slice(-1); -} +/** + * Original function: + * + * 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)}`); + * 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 input is '3' + * The last digit of 105 input is '3' + * The last digit of 806 input is '3' + */ + // Explain why the output is the way it is // =============> write your explanation here + +/** + * Explanation: + * + * The function getLastDigit() is not working properly because: + * It's ignoring the parameter: The function is defined to take a parameter, but when calling the function it's using the global variable num (which is set to 103) instead of the parameter passed to it. + * No parameters in function definition: The function is defined as function getLastDigit() without any parameters, so when we call getLastDigit(42), the 42 is ignored. + * Fixed value: The function always returns the last digit of 103 (which is "3"), regardless of what number is passed to it. + * That's why all three console logs show "3" - they're all getting the last digit of 103, not the numbers 42, 105, and 806 passed. + */ + // Finally, correct the code to fix the problem // =============> write your new code here +const num = 103; + +function getLastDigit(number) { + return number.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)}`); + +function getLastDigit(number) { + return number.toString().slice(-1); +} + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem + +/** + * The key fix was adding a parameter number to the function definition and using that parameter inside the function instead of the global num variable. Now each call to the function getLastDigit() works with the specific number passed to it. + */ + From bd4a0bf66a71cb6d0f11e35f2edf3d5ef9e6a8e5 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 19 Feb 2026 23:45:11 +0000 Subject: [PATCH 09/18] 1-bmi.js committed --- Sprint-2/3-mandatory-implement/1-bmi.js | 20 ++++++++++++++++++-- 1 file changed, 18 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..7e892632f2 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,6 +14,22 @@ // Then when we call this function with the weight and height // It should return their Body Mass Index to 1 decimal place +/** + * Original function: + * function calculateBMI(weight, height) { + * return the BMI of someone based off their weight and height + *} + */ + function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file + // Calculate BMI: weight divided by height squared + const bmi = weight / (height * height); + + // Return the result rounded to 1 decimal place using the built-in Math library + return Math.round(bmi * 10) / 10; +} + +// Test the function +console.log(calculateBMI(70, 1.73)); // Should output: 23.4 +console.log(calculateBMI(80, 1.80)); // Test with another example and returns 24.7 + From ef86b10190e937f6920af2d932fedc3fcb5181a8 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 19 Feb 2026 23:45:39 +0000 Subject: [PATCH 10/18] 2-cases.js committed --- Sprint-2/3-mandatory-implement/2-cases.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..0f1664dea1 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,22 @@ // 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 convertToUpperSnakeCase(inputString) { + // Split the string into words using spaces as separators + const words = inputString.split(' '); + + // Convert each word to uppercase using map() function + const upperWords = words.map(word => word.toUpperCase()); + + // Join the uppercase words with underscores + const upperSnakeString = upperWords.join('_'); + + return upperSnakeString; +} + +// Test the function +console.log(convertToUpperSnakeCase("hello there")); // HELLO_THERE +console.log(convertToUpperSnakeCase("lord of the rings")); // LORD_OF_THE_RINGS +console.log(convertToUpperSnakeCase("UPPER SNAKE CASE")); // UPPER_SNAKE_CASE + From 867c4e46350844cbc0d6154990aa412a28aa6ce5 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 19 Feb 2026 23:46:01 +0000 Subject: [PATCH 11/18] 3-to-pounds.js committed --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 38 +++++++++++++++++++ 1 file changed, 38 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..9932d177b9 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,41 @@ // 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 + + +// REUSABLE FUNCTION SOLUTION: + +function toPounds(penceString) { + // Remove the trailing 'p' character + const penceStringWithoutTrailingPound = penceString.substring( + 0, + penceString.length - 1 + ); + + // Pad with leading zeros to ensure at least 3 characters + const paddedPenceNumberString = penceStringWithoutTrailingPound.padStart(3, "0"); + + // Extract pounds (all except last 2 digits) + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + + // Extract pence (last 2 digits) and ensure it's 2 digits + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + // Return the formatted string + return `£${pounds}.${pence}`; +} + +// TEST THE FUNCTION: + +console.log(toPounds("399p")); // £3.99 +console.log(toPounds("99p")); // £0.99 +console.log(toPounds("5p")); // £0.05 +console.log(toPounds("1000p")); // £10.00 +console.log(toPounds("12345p")); // £123.45 +console.log(toPounds("0p")); // £0.00 + From 938109fc9c5e08dee86876bc0dd1931249ad780c Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 19 Feb 2026 23:46:43 +0000 Subject: [PATCH 12/18] time-format.js committed --- Sprint-2/4-mandatory-interpret/time-format.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8c..02692ae141 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -19,16 +19,54 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +/** + * formatTimeDisplay calls pad three times inside the template literal: once for hours, once for minutes, once for 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 +/** + * Value of num when pad is called first time: + * pad(totalHours) -> num = 0 + */ + // c) What is the return value of pad is called for the first time? // =============> write your answer here +/** + * Return value of pad first time: + * "0".padStart(2, "0") = "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 +/** + * Value of num when pad is called last time: + * Last pad call is pad(remainingSeconds) -> remainingSeconds = 1, so num = 1 + */ + // 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 + +/** + * Return value of last pad call: + * "1".padStart(2, "0") = "01" + */ + +/** + * To recap all responses: + * + * (a) 3 + * (b) 0 + * (c) "00" + * (d) 1 — because remainingSeconds is calculated first and holds 1, then after pad(totalHours) and pad(remainingMinutes) have finished, the final call is with that remainingSeconds variable, which is still 1. + * (e) "01" — because 1 is padded with a leading zero making a two-character string "01". + */ + +// Calling the function formatTimeDisplay passing the 12,000 seconds as argument +console.log(formatTimeDisplay(12000)) //return 03:20:00 + From 73daba76c70b698996055745ac4023467ea1cef4 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 19 Feb 2026 23:47:23 +0000 Subject: [PATCH 13/18] format-time.js committed --- Sprint-2/5-stretch-extend/format-time.js | 111 +++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b8..2385fb3a79 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,114 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +// Test suite for formatAs12HourClock function + +function runTests() { + const testCases = [ + // Edge cases and boundaries + { input: "00:00", expected: "12:00 am", description: "Midnight" }, + { input: "12:00", expected: "12:00 pm", description: "Noon" }, + { input: "00:01", expected: "12:01 am", description: "Just after midnight" }, + { input: "11:59", expected: "11:59 am", description: "Just before noon" }, + { input: "12:01", expected: "12:01 pm", description: "Just after noon" }, + { input: "23:59", expected: "11:59 pm", description: "Just before midnight" }, + + // AM hours + { input: "01:00", expected: "01:00 am", description: "1 AM" }, + { input: "02:30", expected: "02:30 am", description: "2:30 AM" }, + { input: "09:15", expected: "09:15 am", description: "9:15 AM" }, + { input: "11:45", expected: "11:45 am", description: "11:45 AM" }, + + // PM hours + { input: "13:00", expected: "01:00 pm", description: "1 PM" }, + { input: "14:30", expected: "02:30 pm", description: "2:30 PM" }, + { input: "17:45", expected: "05:45 pm", description: "5:45 PM" }, + { input: "22:15", expected: "10:15 pm", description: "10:15 PM" }, + + // Invalid inputs + { input: "24:00", expected: "12:00 am", description: "24:00 (should be midnight)" }, + { input: "25:00", expected: null, description: "Invalid hour > 24" }, + { input: "12:60", expected: null, description: "Invalid minutes > 59" }, + { input: "9:00", expected: null, description: "Missing leading zero" }, + { input: "09-00", expected: null, description: "Wrong separator" }, + { input: "abc", expected: null, description: "Non-numeric input" }, + { input: "", expected: null, description: "Empty string" }, + { input: "12", expected: null, description: "Incomplete time" }, + { input: "12345", expected: null, description: "Too many digits" }, + ]; + + console.log("Running tests for formatAs12HourClock...\n"); + + let passed = 0; + let failed = 0; + + testCases.forEach((testCase, index) => { + try { + const result = formatAs12HourClock(testCase.input); + const passed_test = result === testCase.expected; + + if (passed_test) { + console.log(`Test ${index + 1}: ${testCase.description} - PASSED`); + passed++; + } else { + console.log(`Test ${index + 1}: ${testCase.description} - FAILED`); + console.log(`Input: "${testCase.input}"`); + console.log(`Expected: "${testCase.expected}"`); + console.log(`Got: "${result}"\n`); + failed++; + } + } catch (error) { + console.log(`Test ${index + 1}: ${testCase.description} - ERROR`); + console.log(`Input: "${testCase.input}"`); + console.log(`Error: ${error.message}\n`); + failed++; + } + }); + + console.log(`\nTests completed: ${passed} passed, ${failed} failed`); +} + +// Run the tests +runTests(); + +// Fixed Code: + +function formatAs12HourClock(time) { + // Input validation + if (typeof time !== 'string' || !time) { + return null; + } + + // Check format: HH:MM with leading zeros + const timeRegex = /^([0-1][0-9]|2[0-3]):([0-5][0-9])$/; + if (!timeRegex.test(time)) { + return null; + } + + const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); + + // Handle midnight (00:00) + if (hours === 0) { + return `12:${minutes} am`; + } + + // Handle noon (12:00) and other PM hours + if (hours === 12) { + return `12:${minutes} pm`; + } + + if (hours > 12) { + const pmHours = hours - 12; + // Add leading zero for hours 1-9 + const formattedHours = pmHours < 10 ? `0${pmHours}` : `${pmHours}`; + return `${formattedHours}:${minutes} pm`; + } + + // AM hours (1-11) + // Keep leading zero for hours 1-9 + const formattedHours = hours < 10 ? `0${hours}` : `${hours}`; + return `${formattedHours}:${minutes} am`; +} + From c77fd7dfa866b120b0b2d0bb138eb46ccfde582c Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Thu, 19 Feb 2026 23:48:24 +0000 Subject: [PATCH 14/18] .gitignore added --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2ff82044a6..0fb772f731 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ node_modules .DS_Store .vscode **/.DS_Store -.gitignore .git - +*.swp From 0958092c423c445ea9a08a00170303542a9d8eba Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Wed, 25 Feb 2026 23:28:43 +0000 Subject: [PATCH 15/18] Move the explanation below --- Sprint-2/1-key-errors/1.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 729b0774f5..d799dbb503 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -6,19 +6,11 @@ /** * Prediction: * An error will occur because the function parameter decimalNumber is being redeclared inside the function body using const. This creates a naming conflict - you can't have a parameter and a local variable with the same name. - * Additionally, the console.log(decimalNumber) at the end will cause a ReferenceError because decimalNumber is not defined in the global scope - it's only defined within the function's scope. + * Additionally, the console.log(decimalNumber) at the end will cause a ReferenceError because decimalNumber is not defined in the global scope, it's only defined within the function's scope. */ // Try playing computer with the example to work out what is going on -/** - * Explanation - * The code has two main problems: - * Redeclaration error: The function parameter decimalNumber is being redeclared with const decimalNumber = 0.5 inside the function. In JavaScript, you cannot have a variable with the same name as a parameter in the same scope. - * Scope error: The console.log(decimalNumber) at the end is trying to access a variable that only exists inside the function's scope. Variables declared inside functions are not accessible from the outside. - * Logic error: Even if the scope issues were fixed, the function always returns "50%" regardless of the input because it overwrites the parameter with 0.5. - */ - /** Original function: * * function convertToPercentage(decimalNumber) { @@ -32,6 +24,13 @@ */ // =============> write your explanation here +/** + * Explanation + * The code has two main problems: + * Redeclaration error: The function parameter decimalNumber is being redeclared with const decimalNumber = 0.5 inside the function. In JavaScript, it not possible to have a variable with the same name as a parameter in the same scope. + * Scope error: The console.log(decimalNumber) at the end is trying to access a variable that only exists inside the function's scope. Variables declared inside functions are not accessible from the outside. + * Logic error: Even if the scope issues were fixed, the function always returns "50%" regardless of the input because it overwrites the parameter with 0.5. + */ // Finally, correct the code to fix the problem // =============> write your new code here From 6ae65daa5abe032043f5796a274ca3bc4d3a4d8a Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Wed, 25 Feb 2026 23:36:47 +0000 Subject: [PATCH 16/18] Add parameter name a and b on explanation section --- Sprint-2/2-mandatory-debug/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 8393b40c5e..d10987b6cd 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -17,7 +17,7 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); /** Explanation: * - * The following function takes two arguments as input and display the multiplication result. + * The following function takes two arguments a and b as input and display the multiplication result. * But instead of using the function "console.log" it shoudl use the function "return (a * b)". * That's the reason it displays "undefined". */ From 92fef8937e120570ad6479d9456cc0c247680110 Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Wed, 25 Feb 2026 23:39:59 +0000 Subject: [PATCH 17/18] Add the word explanation on the explanation section to make it more understandble --- Sprint-2/2-mandatory-debug/1.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index bbb4554a5e..f25ceb8041 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -13,7 +13,8 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); */ // =============> write your explanation here - /** The arguments "a + b" should be on the same line as the return so the sum returns that value instead of "undefined" + /** Explanation: + * The arguments "a + b" should be on the same line as the return so the sum returns that value instead of "undefined" */ // Finally, correct the code to fix the problem From dcbef87605163f396629143efc1887da581a502d Mon Sep 17 00:00:00 2001 From: Carlos Abreu Date: Wed, 25 Feb 2026 23:46:01 +0000 Subject: [PATCH 18/18] Reformat the explanation to make it more clear --- Sprint-2/2-mandatory-debug/2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 4ae3c7f00f..0049e86c9e 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -40,7 +40,8 @@ * * The function getLastDigit() is not working properly because: * It's ignoring the parameter: The function is defined to take a parameter, but when calling the function it's using the global variable num (which is set to 103) instead of the parameter passed to it. - * No parameters in function definition: The function is defined as function getLastDigit() without any parameters, so when we call getLastDigit(42), the 42 is ignored. + * There is no parameters in function definition. + * The function is defined as function getLastDigit() without any parameters, so when we call getLastDigit(42), the 42 is ignored. * Fixed value: The function always returns the last digit of 103 (which is "3"), regardless of what number is passed to it. * That's why all three console logs show "3" - they're all getting the last digit of 103, not the numbers 42, 105, and 806 passed. */