From 2f5634835b4d50db77caf48e23d805ec17789efd Mon Sep 17 00:00:00 2001 From: KK Tech Date: Fri, 6 Mar 2026 23:03:19 +0000 Subject: [PATCH 1/3] Completed Sprint-2 --- Sprint-2/1-key-errors/0.js | 9 ++++++++- Sprint-2/1-key-errors/1.js | 15 ++++++++++++++ Sprint-2/1-key-errors/2.js | 10 ++++++++++ Sprint-2/2-mandatory-debug/0.js | 11 ++++++++++ Sprint-2/2-mandatory-debug/1.js | 10 ++++++++++ Sprint-2/2-mandatory-debug/2.js | 20 +++++++++++++++++++ Sprint-2/3-mandatory-implement/1-bmi.js | 7 +++++-- Sprint-2/3-mandatory-implement/2-cases.js | 5 +++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 7 +++++++ Sprint-2/4-mandatory-interpret/time-format.js | 5 +++++ 10 files changed, 96 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..94de4cf788 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,7 @@ // Predict and explain first... // =============> write your prediction here +// This function is trying to capitalise the first letter of a string. +// it takes the first character using str[0], converts it to uppercase,and joins it with the rest of the string using str.slice(1). // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -10,4 +12,9 @@ function capitalise(str) { } // =============> write your explanation here -// =============> write your new code here +// The error is occurring because the function is trying to declare a variable with the same name as the parameter, which is not allowed in JavaScript. +// The variable `str` is being redeclared inside the function, causing a syntax error. +function capitalise(str) { + let result = str[0].toUpperCase() + str.slice(1); + return result; +} diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..f3ec9f28c5 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,6 +2,9 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// I predict this function is trying to convert a decimal number +// into a percentage. It multiples the decimal number by 100 and +// then it adds the % symbol to the end of the number. // Try playing computer with the example to work out what is going on @@ -15,6 +18,18 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); // =============> write your explanation here +// The error happens becouse 'decimalNumber' is already the parameter +// of the function. Inside the function the code tries to declare 'decimalNumber' +// again using the const, which is not allowed. + +// a other problem is that console.log(decimalNumber) is outside +// the function but 'decimalNumber' only exists inside the function. // 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)); diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..654c2919e4 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,27 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// I predict an error will happen becouse the function uses 3 as the parameter +// but parameters should be varible names. Also the code uses "num" inside the +// function even though it was never defiend. function square(3) { return num * num; } // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// The error happens becouse 3 is used as the function parameter but parameters +// must be varible names. Also the code tries to use "num" inside the function even +// though it was never dec;ared. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..5dd9516dab 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,9 @@ // Predict and explain first... // =============> write your prediction here +// I predict the program will print 320 first. +// Then it will print "the result of multipying 10 and 32 is undefined" +// becouse the function logs the result but does not return it. function multiply(a, b) { console.log(a * b); @@ -9,6 +12,14 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// The problem is that the function uses console.log insted ofreturning the value. +// Becouse the function does not return anything, the value of multiply(10, 32) +// becomes undefined when it is used insdie the temple string. // 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)); \ 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..7cea5f00c8 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,8 @@ // Predict and explain first... // =============> write your prediction here +// I predict the program will print "The sum of 10 and 32 is underfined" +// becouse the return statment does not return a value and the addition +// is written on the next line. function sum(a, b) { return; @@ -9,5 +12,12 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// The problem is that the return us written on its own line. +// Becouse of this, the function returns undefined before executing 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)}`); \ 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..3c848633f0 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,11 @@ // Predict the output of the following code: // =============> Write your prediction here +// I predict the program will print: +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 +// This happens because the function always uses the variable num which is 103. const num = 103; @@ -15,10 +20,25 @@ 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 problem is that the function always uses the varible num which is 103. +// Becouse of this, the last digit is always 3. +// The numbers passed into the function (42, 105, 806) are ignored. + // 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 diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..035819faa1 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // 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)); +// return the BMI of someone based off their weight and height diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..4381b2bc77 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.replaceAll(" ", "_").toUpperCase(); +} +console.log(toUpperSnakeCase("hello there")); diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..97bca4826f 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,10 @@ // 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(pence) { + return "£" + (pence / 100).toFixed(2); +} +console.log(toPounds(399)); +console.log(toPounds(250)); +console.log(toPounds(100)); diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8c..6720ba6ef0 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,17 +18,22 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// It will be called 3 times becouse it is used three times in the return line. // 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 is 0 becouse totalHours is 0 when the input is 61 seconds. // c) What is the return value of pad is called for the first time? // =============> write your answer here +// The return value is "00" beccouse padStart adds a 0 in front to make it two digits. // 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 value is 1 becouse remainingSeconds is 1 when the input is 61 seconds. // 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 +// The return value is "01" becouse padStart adds a 0 at the beginning ti make it two digits. From 9a911dddcf8d6631836400d9612e33de3944cf7a Mon Sep 17 00:00:00 2001 From: KK Tech Date: Sat, 7 Mar 2026 15:33:31 +0000 Subject: [PATCH 2/3] improved task --- Sprint-2/3-mandatory-implement/1-bmi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 035819faa1..f427a3dfb6 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,7 +16,7 @@ function calculateBMI(weight, height) { const bmi = weight / (height * height); - return bmi.toFixed(1); + return Number(bmi.toFixed(1)); } console.log(calculateBMI(70, 1.73)); // return the BMI of someone based off their weight and height From 45d6ec829e7664b385d326c0ba03240aa06b41ba Mon Sep 17 00:00:00 2001 From: KK Tech Date: Sun, 8 Mar 2026 13:12:18 +0000 Subject: [PATCH 3/3] improved my work regarding to the feedback --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 97bca4826f..cf6d169a3e 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -5,9 +5,11 @@ // You should call this function a number of times to check it works for different inputs -function toPounds(pence) { - return "£" + (pence / 100).toFixed(2); +function toPounds(penceString) { + const penceNumber = Number(penceString.slice(0, -1)); + return "£" + (penceNumber / 100).toFixed(2); } -console.log(toPounds(399)); -console.log(toPounds(250)); -console.log(toPounds(100)); + +console.log(toPounds("399p")); +console.log(toPounds("250p")); +console.log(toPounds("100p"));