From 65fe894c55650890c8d4d67df0e17368a5f9426b Mon Sep 17 00:00:00 2001 From: Ahmad Date: Mon, 16 Jun 2025 17:22:09 +0100 Subject: [PATCH 01/10] Answered comment for count update in exercise -1 --- Sprint-1/1-key-exercises/1-count.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..49b7b3bdc 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,5 @@ count = count + 1; // 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 +// line 3 increases the value of count by 1. +// the "=" operator assigns the result of "count + 1" back to the variable count. \ No newline at end of file From c2e158f51d6af172f3c2d6f70b68399d36bc30ce Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 27 Jun 2025 17:00:47 +0100 Subject: [PATCH 02/10] predicted and explained the error. and finally, fixed the code. --- Sprint-2/1-key-errors/0.js | 9 +++++++-- Sprint-2/1-key-errors/1.js | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..660c2dd18 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -9,5 +9,10 @@ function capitalise(str) { return str; } -// =============> write your explanation here -// =============> write your new code here +// =============> write your explanation here: when i call the function capitalise with a string input, it shows an error because i am trying to redeclare the variable "str" inside the function, which is already defined as a parameter. this causes a syntax error and we can not redeclare a variable with the same name. +// =============> write your new code here: we can not use let str because str is already the function parameter. + +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..da2d5f4df 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 +// =============> write your prediction here: my prediction: The error will occur because i am trying to redeclare the variable "decimalNumber".// // Try playing computer with the example to work out what is going on @@ -14,7 +14,12 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// =============> write your explanation here: // the error: identifier `decimalNumber` has already been declared. this error shows that identifier has already been declared and we can not redeclare it again.The identifier `decimalNumber` declared in parameter.// // Finally, correct the code to fix the problem // =============> write your new code here +// function convertTopercentage(decimalNumber) { +// const percentage = `${decimalNumber * 100}%`; +// return percentage; +// } +// console.log(convertTopercentge(0.5));// From 5e632d23aaa30828c375cc48c6e2825dd93a1afe Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 27 Jun 2025 17:33:23 +0100 Subject: [PATCH 03/10] the error is predicted before running the code and then explained the error. and finally, rewrote the code to fix the problem. --- Sprint-2/1-key-errors/2.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..a63dc910f 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,22 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> write your prediction of the error here: the error might be inside the function "the square number" or might be num is not identified.// function square(3) { return num * num; } -// =============> write the error message here +// =============> write the error message here: Uncaught syntaxError: Unexpected number.// -// =============> explain this error message here +// =============> explain this error message here: This error occurs because the function parameter is not defined correctly. Instead of passing a number directly, we should use a variable name. In this case, we can use "num" as the parameter name. // Finally, correct the code to fix the problem + // =============> write your new code here +// function square(num) { +// return num * num; +// } From 4cdfdd489e8a85956a428c58b3e3e04f12d9e618 Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 27 Jun 2025 18:00:49 +0100 Subject: [PATCH 04/10] explained the technical error and fixed the code as comment. --- Sprint-2/2-mandatory-debug/0.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..45163bd56 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: the value of a and b is not defined in the function and the return statement is missing.// function multiply(a, b) { console.log(a * b); @@ -8,7 +8,11 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// =============> write your explanation here: The code is running but it has technical issue. the multiply function logs the result but does not return it.We need to use return function to use the result inside the 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)}`); From eb5e0dcda931e576472a1400ca44c13b92087fd1 Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 27 Jun 2025 23:08:53 +0100 Subject: [PATCH 05/10] The sum function is undefined because the function return was written incorrectly. i explained the error and rewrote the code as a comment. --- Sprint-2/2-mandatory-debug/1.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..16b78ee90 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: The return function is not defined, so the function will not return the sum of a and b. function sum(a, b) { return; @@ -8,6 +8,9 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> write your explanation here: in the code above, the function Sum is not returning because the return function is not defined and it is written incorrectly. The return function should be written before the a + b values.// // Finally, correct the code to fix the problem // =============> write your new code here +// function sum(a, b) { +// return a + b; +// } From a696e1795ffadf3cb64e9ac047e085a88e6e255f Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 27 Jun 2025 23:44:35 +0100 Subject: [PATCH 06/10] in this code the function is not working properly. I explained the issue and fixed the code. --- Sprint-2/2-mandatory-debug/2.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..cc08df12d 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,7 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> Write your prediction here: the function const should write inside the call function.// const num = 103; @@ -14,11 +14,19 @@ 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 +// =============> write the output here: The output is 3 for all three calls. // Explain why the output is the way it is -// =============> write your explanation here +// =============> write your explanation here: The function getLastDigit is not taking any parameters, so it always uses the outer variable num, which is 103. That's why the output is always 3. // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> 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 84ed53eed98be4cb90c77ef8b3227236576ddcf9 Mon Sep 17 00:00:00 2001 From: Ahmad Date: Sun, 29 Jun 2025 18:21:44 +0100 Subject: [PATCH 07/10] i returned the Body Mass Index(BMI) of myselfin return function and then explained it in comment how to calculate the BMI. --- Sprint-2/3-mandatory-implement/1-bmi.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..2321bdee0 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,14 @@ // 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 + var bmi = weight / (height * height); + var bmis = bmi.toFixed(1); + return `Your bmi is ${bmis}`; + + // return the BMI of someone based off their weight and height +} +console.log(calculateBMI(85, 1.75)); +// based on the above code: My weight is 85 kg and my height is 1.75m. +// first i squared my height: 1.75 * 1.75 = 3.0625. +// then i divided my weight by the squared height: 85 / 3.0625= 27.8 +// so my BMI is `27.8`. From 7a09127aba2f2051c83d0359a531842b3cae5990 Mon Sep 17 00:00:00 2001 From: Ahmad Date: Mon, 30 Jun 2025 03:27:58 +0100 Subject: [PATCH 08/10] i turned the code into reusable block of code and i called the function many times for different inputs. --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..8c5dc3f5f 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,15 @@ // 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 noP = penceString.slice(0, -1); + const padded = noP.padStart(3, "0"); + const pounds = padded.slice(0, -2); + const pence = padded.slice(-2).padEnd(2, "0"); + return `£${pounds}.${pence}`; +} +console.log(toPounds("5p")); // £0.05 +console.log(toPounds("70p")); // £0.70 +console.log(toPounds("399p")); // £3.99 +console.log(toPounds("1000p")); // £10.00 From f813ae613c49f3413582adb84695c31432578ffd Mon Sep 17 00:00:00 2001 From: Ahmad Date: Mon, 30 Jun 2025 23:05:08 +0100 Subject: [PATCH 09/10] I answered all the questions and python visualiser helped me answer these questions. --- Sprint-2/4-mandatory-interpret/time-format.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..345461728 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,18 +17,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> write your answer here: When formatTimeDisplay is called four times pad will be called, one for remainingSeconds, one for remainingMinutes, one for totalMinutes and one for totalHours. // 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 +// =============> write your answer here: When pad is called for thee first time, num will be assigned the value of 1, which is the value of remainingSeconds. // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> write your answer here: The return value of pad when called for the first time will be `01` because it pads the number 1 with a leading zero 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 +// =============> write your answer here: When pad is called for the last time, num will be assigned the value of 0, which is the value of totalHours. // 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 +// =============> write your answer here: when pad is called for the last time, the return value will be `0` because it pads the number 0 with a leading zero to make it two digits. From 6e2a97e5e8bbb08738555fc79bfc70f909850ef8 Mon Sep 17 00:00:00 2001 From: Ahmad Date: Sat, 12 Jul 2025 21:27:34 +0100 Subject: [PATCH 10/10] Implemented the function called toUpperSnakeCase. --- Sprint-2/3-mandatory-implement/2-cases.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..2de51e31c 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -11,6 +11,17 @@ // Another example: "lord of the rings" should be "LORD_OF_THE_RINGS" +function toUpperSnakeCase(input) { + return input.toUpperCase().replace(/ /g, "_"); +} + +console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE" +console.log(toUpperSnakeCase("lord of the rings")); // "LORD_OF_THE_RINGS" +// in the above code, we are using the toUpperCase method to convert the string to uppercase +// and then using the replace method to replace spaces with underscores. +// This is a simple implementation of the function to convert a string to UPPER_SNAKE_CASE. +// here replace(/ /g, "_") is used to replace all spaces in the string with underscores. + // 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