From 3d1b781a7143be88fcf7c19b0673c641eefb6053 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Sat, 11 Jul 2026 23:50:41 +0100 Subject: [PATCH 01/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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;