From c3bbdff9188a432591de9ca6a6a36afca58879fc Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Mon, 9 Feb 2026 14:39:05 +0000 Subject: [PATCH 01/12] Fixed the errors in the 1-key-errors folder --- Sprint-2/1-key-errors/0.js | 10 ++++++++-- Sprint-2/1-key-errors/1.js | 9 +++++++-- Sprint-2/1-key-errors/2.js | 9 ++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..31dd9f292 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// =============> I think the variable 'str' is repeated twice in string literals. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -9,5 +9,11 @@ function capitalise(str) { return str; } -// =============> write your explanation here +// =============> The error occurs because some parts of the code are not allowed in JS. +// The variable 'str' is already declared in line 7 as a parameter // =============> write your new code here + +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}` +} +console.log(capitalise("shop")); diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..bc2241959 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 +// =============> variable 'decimalNumber' is repeated already declared as a parameter in line 8 // 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 +// =============> Again, the error is a syntax error. +// The variable 'decimal' is already declared as a parameter // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + return `${decimalNumber * 100}%` +} diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..32c77fd77 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,21 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> The error occurs because we have not defined 'num' function square(3) { return num * num; } -// =============> write the error message here +// =============> It is a syntaxError: Enexpected number -// =============> explain this error message here +// =============> In line 8, the number as a parameter is not expected; instead, a variable is expected. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} From 1a63f233f9254b5defbfe0559926309d53efce9f Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Mon, 9 Feb 2026 15:08:59 +0000 Subject: [PATCH 02/12] completed the mandatory debugs --- Sprint-2/2-mandatory-debug/0.js | 10 ++++++++-- Sprint-2/2-mandatory-debug/1.js | 10 ++++++++-- Sprint-2/2-mandatory-debug/2.js | 16 +++++++++++++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..b14599028 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 +// =============> In line 6, the word return is missing, I assume. function multiply(a, b) { console.log(a * b); @@ -8,7 +8,13 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// =============> $`{multiply(10, 32)}` is undefined. // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + return a * b; +} + +console.log(multiply(10, 32)); diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..fce834f88 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 +// =============> It will give an error; line 5 and 6 should be in one line. function sum(a, b) { return; @@ -8,6 +8,12 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> The output is undefined because return and a + b are in two different lines. // Finally, correct the code to fix the problem // =============> write your new code here + +function sum(a, b) { + return a + b; +} + +console.log(sum(10, 32)); diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..f2c64472c 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 +// =============> It will probaby return the last digit as a string. const num = 103; @@ -14,11 +14,21 @@ 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 +// =============> Aha, I was wrong. The outputs for all the console.log is 3 // Explain why the output is the way it is -// =============> write your explanation here +// =============> because, the function takes 'const num = 103' as input. // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(num) { + return num.toString().slice(-1); +} + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem + +// This code should be working better. It takes the last digit of the number as a string +// and at last, change that string into a number; +function getLastDigit(num) { + return Number(num.toString().slice(-1)); +} From 6549aaa4ffb265e5bd33d0a599aa3f4207f89055 Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Mon, 9 Feb 2026 16:42:48 +0000 Subject: [PATCH 03/12] Implement completed --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 ++++-- Sprint-2/3-mandatory-implement/2-cases.js | 7 ++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 22 +++++++++++++++++++ 3 files changed, 34 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..99374a594 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 + let bmi = weight / (height * height); + return Math.round(bmi * 10) / 10 +} + +// console.log(calculateBMI(68, 1.7)); \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..4f821f6f9 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,10 @@ // 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 toUpperSnake(str) { + return str.split(" ").map(item => item.toUpperCase()).join("_"); +} + +console.log(toUpperSnake("lord of the rings")); +// returns LORD_OF_THE_RINGS diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..bce182bb9 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,25 @@ // 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 + +// Method 1 +function toPounds(penceString) { + let penceStringWithoutP = penceString.substring(0, penceString.length - 1); + let paddedPenceNumberString = penceStringWithoutP.padStart(3, "0"); + let pound = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); + let pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2); + + return `£${pound}.${pence}`; + +} +console.log(toPounds("447p")); // £4.47 + + + +// Method 2 +function toPounds(penceString) { + let value = Number(penceString.slice(0, -1)) / 100; + return `£${value.toFixed(2)}` +} + +console.log(toPounds("447p")); // £4.47 From d3bb259725f14907d3037f590ebbb010f7f92ef5 Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Mon, 9 Feb 2026 21:46:57 +0000 Subject: [PATCH 04/12] interpret is done --- Sprint-2/4-mandatory-interpret/time-format.js | 15 ++++++++++----- 1 file changed, 10 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..5fd93b4ff 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,24 +11,29 @@ 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 // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> pad() function will be called 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 +// =============> 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 +// the last pad, shows the remaining seconds (61 % 60 = 1), and it is 1. // 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 +// =============> 01 +// The return value assigned to num when pad is called for the last time shows the seconds and it is 1 From e5372e2142b755437387fdc97bcc559f47fe0c7f Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Mon, 9 Feb 2026 22:11:57 +0000 Subject: [PATCH 05/12] Fixed the format-time function --- Sprint-2/5-stretch-extend/format-time.js | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..956ce1fe8 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -2,14 +2,31 @@ // Make sure to do the prep before you do the coursework // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. +// function formatAs12HourClock(time) { +// const hours = Number(time.slice(0, 2)); +// if (hours > 12) { +// return `${hours - 12}:00 pm`; +// } +// return `${time} am`; +// } + function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; - } - return `${time} am`; + let hours = Number(time.slice(0, 2)); + let minutes = Number(time.slice(3, 5)); + let ampm = hours >= 12 ? 'pm' : 'am'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0'+minutes : minutes; + + return `${hours}:${minutes} ${ampm}` } +console.log(formatAs12HourClock("00:00")); +console.log(formatAs12HourClock("23:59")); +console.log(formatAs12HourClock("12:00")); +console.log(formatAs12HourClock("21:20")); + + const currentOutput = formatAs12HourClock("08:00"); const targetOutput = "08:00 am"; console.assert( From c064497e73b06fb0c07c9ac11011b410351f98cd Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Sun, 15 Feb 2026 14:53:51 +0000 Subject: [PATCH 06/12] gave const name to bmi variable --- 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 99374a594..4647d1323 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,7 +15,7 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - let bmi = weight / (height * height); + const bmi = weight / (height * height); return Math.round(bmi * 10) / 10 } From d377ac2de75be124be9b9c1b6a525c1c623dfbe5 Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Sun, 15 Feb 2026 14:54:25 +0000 Subject: [PATCH 07/12] Changed toUpperCase to toUpperSnakeCase --- Sprint-2/3-mandatory-implement/2-cases.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 4f821f6f9..eaf50b2b4 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -15,7 +15,7 @@ // 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 toUpperSnake(str) { +function toUpperSnakeCase(str) { return str.split(" ").map(item => item.toUpperCase()).join("_"); } From c8da88bfe5f9ea60977976dc9df01fc13a2c01aa Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Sun, 15 Feb 2026 14:59:27 +0000 Subject: [PATCH 08/12] Fixed an issue in format-time.js --- Sprint-2/5-stretch-extend/format-time.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 956ce1fe8..5bbc85c25 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -17,6 +17,7 @@ function formatAs12HourClock(time) { hours = hours % 12; hours = hours ? hours : 12; // the hour '0' should be '12' minutes = minutes < 10 ? '0'+minutes : minutes; + hours = hours < 10 ? '0'+hours : hours; return `${hours}:${minutes} ${ampm}` } From 0800bae0e06bf4fa8f764432170433a6569a21aa Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Sun, 15 Feb 2026 19:19:39 +0000 Subject: [PATCH 09/12] fixed the error --- Sprint-2/3-mandatory-implement/2-cases.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index eaf50b2b4..52d8d73e7 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -19,5 +19,5 @@ function toUpperSnakeCase(str) { return str.split(" ").map(item => item.toUpperCase()).join("_"); } -console.log(toUpperSnake("lord of the rings")); +console.log(toUpperSnakeCase("lord of the rings")); // returns LORD_OF_THE_RINGS From 974fb6286e95f92a89be7ab80c35e911d14da29f Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Sun, 15 Feb 2026 19:25:52 +0000 Subject: [PATCH 10/12] changed let to const --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index bce182bb9..b91002ec2 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -21,7 +21,7 @@ console.log(toPounds("447p")); // £4.47 // Method 2 function toPounds(penceString) { - let value = Number(penceString.slice(0, -1)) / 100; + const value = Number(penceString.slice(0, -1)) / 100; return `£${value.toFixed(2)}` } From a9ad155477a118d0361db109139215709b53a7a6 Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Sun, 15 Feb 2026 20:57:12 +0000 Subject: [PATCH 11/12] Changed let to const in 3-to-pounds.js file --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index b91002ec2..09067fedb 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -7,10 +7,10 @@ // Method 1 function toPounds(penceString) { - let penceStringWithoutP = penceString.substring(0, penceString.length - 1); - let paddedPenceNumberString = penceStringWithoutP.padStart(3, "0"); - let pound = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); - let pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2); + const penceStringWithoutP = penceString.substring(0, penceString.length - 1); + const paddedPenceNumberString = penceStringWithoutP.padStart(3, "0"); + const pound = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); + const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2); return `£${pound}.${pence}`; From 155d15f088d74a7b2ad00b93c653bc9fd81128a7 Mon Sep 17 00:00:00 2001 From: Fida Ali Zada Date: Mon, 16 Feb 2026 12:17:02 +0000 Subject: [PATCH 12/12] changed let to const in format-time.js file --- Sprint-2/5-stretch-extend/format-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 5bbc85c25..4348f25a1 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -13,7 +13,7 @@ function formatAs12HourClock(time) { let hours = Number(time.slice(0, 2)); let minutes = Number(time.slice(3, 5)); - let ampm = hours >= 12 ? 'pm' : 'am'; + const ampm = hours >= 12 ? 'pm' : 'am'; hours = hours % 12; hours = hours ? hours : 12; // the hour '0' should be '12' minutes = minutes < 10 ? '0'+minutes : minutes;