From 3d1b781a7143be88fcf7c19b0673c641eefb6053 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Sat, 11 Jul 2026 23:50:41 +0100 Subject: [PATCH 01/20] Corrected Error by Assigning Value --- Sprint-2/1-key-errors/0.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..0a6826cf6e 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -5,9 +5,16 @@ // 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; } - +let str = 'hello'; +console.log(capitalise(str)); // =============> write your explanation here // =============> write your new code here +//By capitilise(str)-> we have created a function with parameter str. +// Inside the function, `str` is already declared as a local variable because it is a parameter. +// We can't declare another variable with the same name using `let` in the same scope. +// It was giving an error because we were trying to declare `str` again using `let`. +// I corrected it by removing `let` because we don't need to create another variable with the same name; we just have to assign a new value to the existing `str`. +// Outside the function, I created another variable with the same name, `str`. We can do this because it is in a different scope. From c8b7d5af5aeb7440c628b3b0192c31fc038fa889 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Sun, 12 Jul 2026 00:07:53 +0100 Subject: [PATCH 02/20] make some changes in file 0.js --- Sprint-2/1-key-errors/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 0a6826cf6e..2cc6ce4b16 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here - +// The Error will occur because we are trying to create a variable with same name in same scope. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring From c45088de5af4ef25cf5c3cedea8ae8c65a43fc4a Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Sun, 12 Jul 2026 12:13:43 +0100 Subject: [PATCH 03/20] Fixed Errors for 1.js --- Sprint-2/1-key-errors/1.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..6b92d519f8 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,19 +2,47 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// There're two errors. +// First Error will be, the function having a parameter decimalNumber, and we are trying to declare another variable with same which we can't be able to do. +// And decimalNumber is a local variable , we cannot use it outside of the function/scope. + // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { +/*function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +console.log(decimalNumber);*/ + +function convertToPercentage(decimalNumber) { + decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + return percentage; +} +const decimalNumber= 0.9; +console.log(decimalNumber); +console.log(convertToPercentage(decimalNumber)); // =============> write your explanation here // Finally, correct the code to fix the problem // =============> write your new code here + +// By function convertToPercentage(decimalNumber) -> we have created a function with the parameter decimalNumber. +// Inside the function, `decimalNumber` is already declared as a local variable because it is a parameter. +// We can't declare another variable with the same name using `const` in the same scope. +// we need to assign a value to the variable. +// Outside of the function we are trying to print the value of decimalNumber but we haven't declare the variable nor assign a value. +// And decimalNumber is a new variable as its outside of the scope now, so if we want we can create a variable with the name used before in a function +// because its in different scope. +// I have created a const variable and assigned a value to it. +// And lastly, I have called function and passed decimalNumber as an argument and print the value what's function is returning. +// The percentage is calculated by decimalNumber = 0.5 not 0.9 +// As we passed decimalNumber as an argument with the value of 0.9 but inside the function we are assigning a value to the +// decimalNumber so its value will be overwritten with parameter's local value and percentage will be calculated with decimalNumber=0.5 +// If we don't assign a value inside the function then percentage will be calculated on the basis of the argument we passed, +// though outside of const decimalNumber will be unchanged and remained 0.9. \ No newline at end of file From 616dc240049aaa4610f89052db77a7e22920d63f Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Sun, 12 Jul 2026 13:09:48 +0100 Subject: [PATCH 04/20] Fixed Errors for 1.js --- Sprint-2/1-key-errors/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 6b92d519f8..edb5afd458 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -43,6 +43,6 @@ console.log(convertToPercentage(decimalNumber)); // And lastly, I have called function and passed decimalNumber as an argument and print the value what's function is returning. // The percentage is calculated by decimalNumber = 0.5 not 0.9 // As we passed decimalNumber as an argument with the value of 0.9 but inside the function we are assigning a value to the -// decimalNumber so its value will be overwritten with parameter's local value and percentage will be calculated with decimalNumber=0.5 +// decimalNumber, its value will be overwritten with parameter's local value and percentage will be calculated with decimalNumber=0.5 // If we don't assign a value inside the function then percentage will be calculated on the basis of the argument we passed, // though outside of const decimalNumber will be unchanged and remained 0.9. \ No newline at end of file From 815729eaecbb24a2cb614a30f260fd24357fbcbf Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Sun, 12 Jul 2026 15:43:13 +0100 Subject: [PATCH 05/20] Fixed Erros for 2.js --- Sprint-2/1-key-errors/2.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..ecab91e3cd 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,23 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +//We cannot use number as a parameter. It should be any variable. -function square(3) { +/*function square(3) { return num * num; -} - +}*/ // =============> write the error message here - +//The error message is, 'Unexpected number'. // =============> explain this error message here - +// it says unexpected in terms, javaScript doesn't expect number/value as a parameter. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num){ + return num*num; +} + +const result = square(3); +console.log(result); \ No newline at end of file From 5e3518c5a4bf70e0db873cb9409a4813dafa1a50 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Mon, 13 Jul 2026 12:10:34 +0100 Subject: [PATCH 06/20] Fixed Return statment --- Sprint-2/2-mandatory-debug/0.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..dedba67684 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 - -function multiply(a, b) { +// In this example function is being called but as there's no return statement so it will return undefined. +// and a *b multiplication. and the line on line 10 +/*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 - +// I fixed it by adding a return statement and create another variable outside of the function that stores, +//value of function. // Finally, correct the code to fix the problem // =============> write your new code here +function multiply(a, b) { + return (a*b); +} +const result = multiply(10,32); +console.log(`The result of multiplying 10 and 32 is ${result}`); From 698726bdde305baeaf63c86b0a5d08fae43e8b2b Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Mon, 13 Jul 2026 12:12:37 +0100 Subject: [PATCH 07/20] Fixed code for 1.js --- Sprint-2/2-mandatory-debug/1.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..e600ba77ed 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,24 @@ // Predict and explain first... // =============> write your prediction here - -function sum(a, b) { +//It will give an error as we have to mention what are we returning, by simply putting the return statement doesn't automatically +//return anything, except undefined, and then we are doing an addition of two number but we haven't return the result of it, +//when the function will be called in line 11, it will print undefined with the sentence mentioned in literals. +/*function sum(a, b) { return; a + b; } -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/ // =============> write your explanation here +//I firstly fixed the return statement. +//outside of the function I create another variable that stores function value. + // Finally, correct the code to fix the problem // =============> write your new code here + +function sum(a, b) { + return a+b; +} +const result = sum(10,32); +console.log(`The sum of 10 and 32 is ${result}`); \ No newline at end of file From 5ddb2338496af613f7313acd34873203c415bc31 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Wed, 15 Jul 2026 16:14:39 +0100 Subject: [PATCH 08/20] Fixed Function's Paramter for 2.js --- Sprint-2/2-mandatory-debug/2.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..2ec11d3dfc 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,8 +2,10 @@ // Predict the output of the following code: // =============> Write your prediction here - -const num = 103; +// we are using the constant variable num, which is declared as a global variable. Inside function, we have declare it with no +// parameter, but, while calling a function we're passing an argument. It can't use that argument because function is declare +// with no parameter so it will use the global variable whenever the function is being called. +/*const num = 103; function getLastDigit() { return num.toString().slice(-1); @@ -11,14 +13,27 @@ 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)}`); +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 +// it's returning 3 for all three digits which is wrong for that digits // Explain why the output is the way it is // =============> write your explanation here +//This is happening because function is declare with no parameters as I predict and my prediction is totally right as javaScript +//doesn't allow to use argument when there's no parameters. // 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 +// it wasn't working because we are passing argument without declaring function with a parameter and function was using +//global variable whenever the function is being called, so it was returning the last digit of that value stored in global variable. \ No newline at end of file From fcd51d74fc6aba81c6e300fccc2f6d4e1513d427 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Wed, 15 Jul 2026 16:19:00 +0100 Subject: [PATCH 09/20] Programme to Calculate BMI --- Sprint-2/3-mandatory-implement/1-bmi.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..f0ad21966e 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,12 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + const squareHeight = height * height; + const div = weight / height; + const result = div.toFixed(1); + return result; +} +const height = 2.3; +const weight = 64; +const result = calculateBMI(weight, height); +console.log(result); \ No newline at end of file From 4ac532b8be453e213858aa8f74900559aef75091 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Wed, 15 Jul 2026 17:14:16 +0100 Subject: [PATCH 10/20] Programme to convert string in UpperCase with Underscore --- Sprint-2/3-mandatory-implement/2-cases.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..d23b87cd84 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,17 @@ // 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 SnakeUpperCase(str){ + var result = str.toUpperCase(); + let strLength = result.length; + for (let i=0; i Date: Wed, 15 Jul 2026 17:17:14 +0100 Subject: [PATCH 11/20] Function to convert into pounds --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 18 ++++++++++++++++++ 1 file changed, 18 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..5601368820 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,21 @@ // 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 ConversionPenceToPounds(penceString){ + const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1); + paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + pounds = paddedPenceNumberString.substring( 0,paddedPenceNumberString.length - 2); + paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + pounds = paddedPenceNumberString.substring( 0,paddedPenceNumberString.length - 2); + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + const result = `£${pounds}.${pence}`; + return result; +} +const pencestring1 = ConversionPenceToPounds("663p"); +const pencestring2 = ConversionPenceToPounds("98p"); +const pencestring3 = ConversionPenceToPounds("986p"); +console.log(pencestring1); +console.log(pencestring2); +console.log(pencestring3); \ No newline at end of file From 952149c15423332afec99bf9de157909bfe43af0 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Wed, 15 Jul 2026 17:20:13 +0100 Subject: [PATCH 12/20] Interpreted Programme --- Sprint-2/4-mandatory-interpret/time-format.js | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..fe0d95a004 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -1,19 +1,21 @@ -function pad(num) { - let numString = num.toString(); - while (numString.length < 2) { +function pad(num) { //1)num=0, 2)num=0 3) num=1 + let numString = num.toString(); // (last time) numString = "1" + while (numString.length < 2) { //"01" it will return 01 numString = "0" + numString; } return numString; } -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; +function formatTimeDisplay(seconds) { + const remainingSeconds = seconds % 60; //61%60 = 1 + const totalMinutes = (seconds - remainingSeconds) / 60; //1-1=0 + const remainingMinutes = totalMinutes % 60; //0 + const totalHours = (totalMinutes - remainingMinutes) / 60; // 0 - return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; + 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 +24,21 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here - +//3 in console.log // 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 - +//0 // c) What is the return value of pad is called for the first time? // =============> write your answer here - +//"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 - +////1)num=0, 2)num=0 3) num=1, when num is called for last time that is when pad(remainingSeconds), +//here remainingseconds value = 1 so num is assigned with value of 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 +//when pad called for the last time, the value of num is 1 +//it will convert into string by toString method "1" as its less than 2, it satisfies the while loop condition and, +// will concatenate with "0" the final value of variable numString would be "01", and will return "01". From 0cfe806e4c57cba0a98519e7b8599c38ac30c66a Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Wed, 15 Jul 2026 17:21:21 +0100 Subject: [PATCH 13/20] write and test edge cases --- Sprint-2/5-stretch-extend/format-time.js | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b8..607d9dd874 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,31 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); +const currentOutput3 = formatAs12HourClock("00:00"); +const targetOutput3 = "00:00 am"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("24:00"); +const targetOutput4 = "12:00 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("12:00"); +const targetOutput5 = "12:00 am"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput}` +); + +const currentOutput5 = formatAs12HourClock(":00"); +const targetOutput5 = "12:00 am"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput}` +); + From d07c452e6e91ac414efe9e254ac766fd640a30e8 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Thu, 16 Jul 2026 00:50:09 +0100 Subject: [PATCH 14/20] Update Function's parameter for 2.js --- Sprint-2/2-mandatory-debug/2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 2ec11d3dfc..d9c662005e 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,8 +2,8 @@ // Predict the output of the following code: // =============> Write your prediction here -// we are using the constant variable num, which is declared as a global variable. Inside function, we have declare it with no -// parameter, but, while calling a function we're passing an argument. It can't use that argument because function is declare +// we are using the constant variable num, and it is declared as a global variable. The function is declared with no +// parameter, but, while calling a function we're passing an argument. It can't use that argument as function is declare // with no parameter so it will use the global variable whenever the function is being called. /*const num = 103; From 80d46f66cc142da1ac109c20219ef7f4a3148700 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Mon, 20 Jul 2026 18:41:17 +0100 Subject: [PATCH 15/20] Upadte function by removing reassignment of paramter --- Sprint-2/1-key-errors/1.js | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index edb5afd458..5633050255 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -3,9 +3,8 @@ // Why will an error occur when this program runs? // =============> write your prediction here // There're two errors. -// First Error will be, the function having a parameter decimalNumber, and we are trying to declare another variable with same which we can't be able to do. -// And decimalNumber is a local variable , we cannot use it outside of the function/scope. - +//The first error occurs because the function has a parameter called decimalNumber, and we are trying to declare another variable with the same name using const. We cannot declare the same variable twice in the same scope. +//The second error occurs because decimalNumber is a local variable inside the function. Therefore, we cannot use it outside the function’s scope unless we declare another variable called decimalNumber outside the function. // Try playing computer with the example to work out what is going on @@ -19,12 +18,11 @@ console.log(decimalNumber);*/ function convertToPercentage(decimalNumber) { - decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -const decimalNumber= 0.9; +const decimalNumber= 0.9; // I have checked it by assigning different values, and it gives different output for different inputs. console.log(decimalNumber); console.log(convertToPercentage(decimalNumber)); // =============> write your explanation here @@ -32,17 +30,15 @@ console.log(convertToPercentage(decimalNumber)); // Finally, correct the code to fix the problem // =============> write your new code here -// By function convertToPercentage(decimalNumber) -> we have created a function with the parameter decimalNumber. -// Inside the function, `decimalNumber` is already declared as a local variable because it is a parameter. -// We can't declare another variable with the same name using `const` in the same scope. -// we need to assign a value to the variable. -// Outside of the function we are trying to print the value of decimalNumber but we haven't declare the variable nor assign a value. -// And decimalNumber is a new variable as its outside of the scope now, so if we want we can create a variable with the name used before in a function -// because its in different scope. -// I have created a const variable and assigned a value to it. -// And lastly, I have called function and passed decimalNumber as an argument and print the value what's function is returning. -// The percentage is calculated by decimalNumber = 0.5 not 0.9 -// As we passed decimalNumber as an argument with the value of 0.9 but inside the function we are assigning a value to the -// decimalNumber, its value will be overwritten with parameter's local value and percentage will be calculated with decimalNumber=0.5 -// If we don't assign a value inside the function then percentage will be calculated on the basis of the argument we passed, -// though outside of const decimalNumber will be unchanged and remained 0.9. \ No newline at end of file +/* +By writing function convertToPercentage(decimalNumber), we have created a function with a parameter called 'decimalNumber'. +Inside the function, decimalNumber is already declared as a local variable because it is a parameter. Therefore, we cannot declare another variable with the same name using const in the same scope. +However, we can assign a new value to the parameter without using const. For example: +decimalNumber = 0.5; +If we assign 0.5 to the parameter inside the function, the value passed as the argument will be overwritten inside that function call. Therefore, even if we pass 0.8 as the argument, the percentage will be calculated using 0.5, and the function will return 50%. +This reassignment only changes the local parameter inside the function. It does not change the const decimalNumber = 0.9 variable declared outside the function. Therefore, the outside variable will still remain 0.9. +In the original code, we also tried to print decimalNumber outside the function, but no variable with that name had been declared in the outside scope. This would cause a ReferenceError. +In the corrected code, I created a new const variable called decimalNumber outside the function and assigned it the value 0.9. This variable is different from the function parameter because they are in different scopes, so they can have the same name. +Finally, I removed the line that reassigned 0.5 to the parameter, so the function now uses the value passed as the argument. Since the value passed is 0.9, the function returns 90%. +Finally, console.log(decimalNumber) prints 0.9, and console.log(convertToPercentage(decimalNumber)) prints 90%. +*/ \ No newline at end of file From b1c4bb0d43ec17edb4b3277add610921af692550 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Mon, 20 Jul 2026 19:39:55 +0100 Subject: [PATCH 16/20] Update function --- Sprint-2/3-mandatory-implement/2-cases.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index d23b87cd84..5bd8fa2c61 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -15,16 +15,11 @@ // 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 SnakeUpperCase(str){ - var result = str.toUpperCase(); - let strLength = result.length; - for (let i=0; i Date: Mon, 20 Jul 2026 19:46:01 +0100 Subject: [PATCH 17/20] Corrected BMI formula --- 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 f0ad21966e..3910cf666b 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -17,7 +17,7 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height const squareHeight = height * height; - const div = weight / height; + const div = weight / squareHeight; const result = div.toFixed(1); return result; } From 766e9b5827e60c56af8ff8737359562d1ccf8c16 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Mon, 20 Jul 2026 20:56:41 +0100 Subject: [PATCH 18/20] Update function for 3-to-pounds.js --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 5601368820..19a42d79ee 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,21 +4,29 @@ // 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 ConversionPenceToPounds(penceString){ +function toPounds(penceString){ const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1); - paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); - pounds = paddedPenceNumberString.substring( 0,paddedPenceNumberString.length - 2); - paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); - pounds = paddedPenceNumberString.substring( 0,paddedPenceNumberString.length - 2); + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( 0,paddedPenceNumberString.length - 2); const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); const result = `£${pounds}.${pence}`; return result; } -const pencestring1 = ConversionPenceToPounds("663p"); -const pencestring2 = ConversionPenceToPounds("98p"); -const pencestring3 = ConversionPenceToPounds("986p"); -console.log(pencestring1); -console.log(pencestring2); -console.log(pencestring3); \ No newline at end of file +const penceString1 = toPounds("663p"); +const penceString2 = toPounds("98p"); +const penceString3 = toPounds("986p"); +const penceString4 = toPounds("9p"); +const penceString5 = toPounds("15p"); +const penceString6 = toPounds("100p"); +const penceString7 = toPounds("1p"); + + +console.log(penceString1); +console.log(penceString2); +console.log(penceString3); +console.log(penceString4); +console.log(penceString5); +console.log(penceString6); +console.log(penceString7); \ No newline at end of file From 0772043f15030e68f909a7451f7fb44794172d4e Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Fri, 31 Jul 2026 20:58:51 +0100 Subject: [PATCH 19/20] Update format time --- Sprint-2/5-stretch-extend/format-time.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 607d9dd874..885695a0e8 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,6 +4,12 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + if (hours === 0 || hours===24){ + return '12:00 am'; + } + if (hours === 12){ + return `${hours}:00 pm`; + } if (hours > 12) { return `${hours - 12}:00 pm`; } @@ -24,30 +30,22 @@ console.assert( `current output: ${currentOutput2}, target output: ${targetOutput2}` ); const currentOutput3 = formatAs12HourClock("00:00"); -const targetOutput3 = "00:00 am"; +const targetOutput3 = "12:00 am"; console.assert( currentOutput3 === targetOutput3, `current output: ${currentOutput3}, target output: ${targetOutput3}` ); const currentOutput4 = formatAs12HourClock("24:00"); -const targetOutput4 = "12:00 pm"; +const targetOutput4 = "12:00 am"; console.assert( currentOutput4 === targetOutput4, `current output: ${currentOutput4}, target output: ${targetOutput4}` ); const currentOutput5 = formatAs12HourClock("12:00"); -const targetOutput5 = "12:00 am"; +const targetOutput5 = "12:00 pm"; console.assert( currentOutput5 === targetOutput5, - `current output: ${currentOutput5}, target output: ${targetOutput}` + `current output: ${currentOutput5}, target output: ${targetOutput5}` ); - -const currentOutput5 = formatAs12HourClock(":00"); -const targetOutput5 = "12:00 am"; -console.assert( - currentOutput5 === targetOutput5, - `current output: ${currentOutput5}, target output: ${targetOutput}` -); - From 11379668f8f1a1f06fe887b36d25b0d3ef056ac5 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Wed, 5 Aug 2026 11:23:33 +0100 Subject: [PATCH 20/20] Update format time --- Sprint-2/5-stretch-extend/format-time.js | 42 ++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 885695a0e8..82230b75e2 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,14 +4,17 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3,5); if (hours === 0 || hours===24){ - return '12:00 am'; + return `12:${minutes} am`; } if (hours === 12){ - return `${hours}:00 pm`; + return `${hours}:${minutes} pm`; } if (hours > 12) { - return `${hours - 12}:00 pm`; + const convertHours = hours - 12; + const formatHours = String(convertHours).padStart(2, "0"); + return `${formatHours}:${minutes} pm`; } return `${time} am`; } @@ -22,7 +25,6 @@ console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` ); - const currentOutput2 = formatAs12HourClock("23:00"); const targetOutput2 = "11:00 pm"; console.assert( @@ -35,17 +37,45 @@ console.assert( currentOutput3 === targetOutput3, `current output: ${currentOutput3}, target output: ${targetOutput3}` ); - const currentOutput4 = formatAs12HourClock("24:00"); const targetOutput4 = "12:00 am"; console.assert( currentOutput4 === targetOutput4, `current output: ${currentOutput4}, target output: ${targetOutput4}` ); - const currentOutput5 = formatAs12HourClock("12:00"); const targetOutput5 = "12:00 pm"; console.assert( currentOutput5 === targetOutput5, `current output: ${currentOutput5}, target output: ${targetOutput5}` ); +const currentOutput6 = formatAs12HourClock("13:30"); +const targetOutput6 = "01:30 pm"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}` +); +const currentOutput7 = formatAs12HourClock("15:45"); +const targetOutput7 = "03:45 pm"; +console.assert( + currentOutput7 === targetOutput7, + `current output: ${currentOutput7}, target output: ${targetOutput7}` +); +const currentOutput8 = formatAs12HourClock("20:15"); +const targetOutput8 = "08:15 pm"; +console.assert( + currentOutput8 === targetOutput8, + `current output: ${currentOutput8}, target output: ${targetOutput8}` +); +const currentOutput9 = formatAs12HourClock("12:30"); +const targetOutput9 = "12:30 pm"; +console.assert( + currentOutput9 === targetOutput9, + `current output: ${currentOutput9}, target output: ${targetOutput9}` +); +const currentOutput10 = formatAs12HourClock("00:30"); +const targetOutput10 = "12:30 am"; +console.assert( + currentOutput10 === targetOutput10, + `current output: ${currentOutput10}, target output: ${targetOutput10}` +); \ No newline at end of file