From 10193332ad183531b6bcfc858d220fc8281d6f4c Mon Sep 17 00:00:00 2001 From: Dagim-Daniel Date: Fri, 26 Jun 2026 23:04:43 +0100 Subject: [PATCH 1/4] Sprint 2 step 1 (key errors) all tasks under it has been done --- Sprint-2/1-key-errors/0.js | 9 +++++++-- Sprint-2/1-key-errors/1.js | 16 ++++++++++++---- Sprint-2/1-key-errors/2.js | 17 +++++++++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..bc683a58e6 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,18 @@ // Predict and explain first... -// =============> write your prediction here + // it will be reference error because the variable str is being declared twice, once as a parameter and once inside the function body. // 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)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } // =============> write your explanation here + // the error is occurring because the variable str is being declared twice, once as a parameter and once inside the function body. + //removing the let keyword would fix this error, for the function to work properly. + // =============> write your new code here + let firstCapitalised = capitalise("hello"); +console.log(firstCapitalised); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..dff2c088f9 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,9 +2,9 @@ // Why will an error occur when this program runs? // =============> write your prediction here - + // i predict that the error will be a syntax error because the variable decimalNumber is being declared twice, once as a parameter and once inside the function body // Try playing computer with the example to work out what is going on - +/* function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; @@ -13,8 +13,16 @@ function convertToPercentage(decimalNumber) { } console.log(decimalNumber); - +*/ // =============> write your explanation here - + // removing the const keyword would fix this error, for the function to work properly. // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + return percentage; +} +let converted = convertToPercentage(0.5); +console.log(converted); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..b9df4938a6 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,29 @@ // Predict and explain first BEFORE you run any code... + // num is not defined at all, so when the function is called it will throw a reference error. + // and inside the function the parameter is not defined correctly, it should be num instead of 3. // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here - +// reference error because the parameter is not defined correctly, it should be num instead of 3. +/* below is the original code function square(3) { return num * num; } +*/ // =============> write the error message here - + // the error was syntaxError: unexpected number. // =============> explain this error message here - + // because the parameter is not defined correctly, it should be num instead of 3. so the function is not defined correctly and it will throw a syntax error. // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; + +} +let result = square(3); +console.log(result); From ef52ab78dbb0cd03fa97f7d341f01e79338e6a1a Mon Sep 17 00:00:00 2001 From: Dagim-Daniel Date: Sat, 27 Jun 2026 19:01:11 +0100 Subject: [PATCH 2/4] Sprint 2 all tasks under mandatory-debug are done --- Sprint-2/2-mandatory-debug/0.js | 13 ++++++++++--- Sprint-2/2-mandatory-debug/1.js | 14 ++++++++++++-- Sprint-2/2-mandatory-debug/2.js | 18 +++++++++++++++--- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..1ec878f05f 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,21 @@ // Predict and explain first... // =============> write your prediction here - + // there is no return statement in the multiply function, so when we try to log the result of the function call, it will return undefined. +/* original code 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 - + // console.log will do the multiplication of a and b and print the result to the console, but it will not return any value. + // there is no operation done here. just for testing purpose not actual operation. // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + console.log(a * b); + return a * b; // new code added to return the result of the multiplication. +} \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..0e907b3928 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,23 @@ // Predict and explain first... // =============> write your prediction here - + //we have to delete the semicolon used after the return statement in the sum function, because it will terminate the function and return undefined. + /* below is the original code function sum(a, b) { return; a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - +*/ // =============> write your explanation here + // same as my prediction. // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; // removed the semicolon after the return statement to fix the problem. + // and also assigned the value of a + b to the return statement so that it will return the sum of a and b. + // unlike my prediction removing the semicolon only wont do the fix. because in javascript there is a feature called automatic semicolon insertion which will automatically insert a semicolon after the return statement + // when playing computer with this code it will read return with out ; as same as with it. - same error result +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..3b4de82f43 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,8 +2,11 @@ // Predict the output of the following code: // =============> Write your prediction here - -const num = 103; + // the console.log statement will print the last digit of the number 103, which is 3. for all 3 cases. + // since the num variable is declared is global scope, it will always return the last digit of 103. + // the function loses the feature of reusability because it is not taking any parameter to work with, it is always working with the global variable num. +/* original code + const num = 103; function getLastDigit() { return num.toString().slice(-1); @@ -12,13 +15,22 @@ function getLastDigit() { 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 output is the same as my prediction, it will print the last digit of the number 103, which is 3. for all 3 cases. // Explain why the output is the way it is // =============> write your explanation here + // like i explained in my prediction, since the num variable is declared is global scope, it will always return the last digit of 103. // 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 From 784d4653f7121936f9caf8cc678aa11c48043d44 Mon Sep 17 00:00:00 2001 From: Dagim-Daniel Date: Sat, 27 Jun 2026 20:36:43 +0100 Subject: [PATCH 3/4] Sprint 2 all tasks under mandatory-implement and mandatory- interpret has been done --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 +++++- Sprint-2/3-mandatory-implement/2-cases.js | 9 ++++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 23 +++++++++++++++++++ Sprint-2/4-mandatory-interpret/time-format.js | 11 +++++---- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..dd99f24307 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,9 @@ 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); // toFixed() method is used to format the BMI value to 1 decimal place +} +let result = calculateBMI(70, 1.73); // Example usage of the function with weight 70kg and height 1.73m +console.log(`The BMI is ${result}`); // Output the result to the console. diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..9746e32d69 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,12 @@ // 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(inString) { + const outPutString = inString.toUpperCase().replaceAll(" ","_"); + return outPutString; +} +let output1 = toUpperSnakeCase("hello there"); +let output2 = toUpperSnakeCase("lord of the rings"); +console.log(`The result for output1 is : ${output1}. +The result for output2 is : ${output2}.`) \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..1272c04d20 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,26 @@ // 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 penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1); +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // pad the string with leading zeros to ensure it has at least 3 characters +const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2); // get the substring representing the pounds by taking all characters except the last two +const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); // get the substring representing the pence by taking the last two characters and padding it with a "0" if necessary +console.log(`£${pounds}.${pence}`); // + + */ + +function toPounds(penceString){ +const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1); +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // pad the string with leading zeros to ensure it has at least 3 characters +const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2); // get the substring representing the pounds by taking all characters except the last two +const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); // get the substring representing the pence by taking the last two characters and padding it with a "0" if necessary + + return `£${pounds}.${pence}` +} +let output1 = toPounds("500p"); +let output2 = toPounds("399p"); +let output3 = toPounds("2000p"); +console.log(`${output1} +${output2} +${output3}`); \ No newline at end of file diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..c970a1b323 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -14,7 +14,7 @@ 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 @@ -22,17 +22,18 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here - + // 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 - + // the value assigned to num is 0 // c) What is the return value of pad is called for the first time? // =============> write your answer here - + // the return value is "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 last call to pad is with remainingSeconds, which is 1. so num =1. // 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 + // pad returns "01" because it pads the single-digit "1" with a leading "0" \ No newline at end of file From 9c0fba7f6c30e1003466e8ce0668f22eb922629c Mon Sep 17 00:00:00 2001 From: Dagim-Daniel Date: Wed, 1 Jul 2026 14:10:03 +0100 Subject: [PATCH 4/4] sprint 2 step 1 key errors convert to percentage - fix it to convert for different inputs --- Sprint-2/1-key-errors/1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index dff2c088f9..63c2053d9a 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -20,9 +20,9 @@ console.log(decimalNumber); // =============> write your new code here function convertToPercentage(decimalNumber) { - decimalNumber = 0.5; + //decimalNumber = 0.5; // removing this makes work for different inputs const percentage = `${decimalNumber * 100}%`; return percentage; } -let converted = convertToPercentage(0.5); +let converted = convertToPercentage(2.8); console.log(converted); \ No newline at end of file