From 2300ec7505b2d9c3c2f0bd69aecfd4ccf3c358a2 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 20 Sep 2026 19:53:16 +0100 Subject: [PATCH 01/27] Add comments for count variable and assignment Added comments to explain variable declaration and assignment. --- Sprint-2/1-key-exercises/1-count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..bf906426d 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -3,4 +3,5 @@ let count = 0; count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 +// Describe whaWt line 3 is doing, in particular focus on what = is doing // Describe what line 3 is doing, in particular focus on what = is doing From a9cb5667309b27b91f584b14acd55487e74b614b Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Tue, 29 Sep 2026 11:23:49 +0100 Subject: [PATCH 02/27] Fix capitalise function variable redeclaration --- Sprint-3/1-key-errors/0.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..7c0a64325 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,7 +1,14 @@ // Predict and explain first... -// =============> write your prediction here - +// =============> We will have syntax error because string is the parameter of the function and the next line,it is declared wit let +//so it is declared two times in one part // call the function capitalise with a string input + + +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} +console.log(capitalise("mother")); // interpret the error message and figure out why an error is occurring function capitalise(str) { @@ -9,5 +16,8 @@ function capitalise(str) { return str; } -// =============> write your explanation here -// =============> write your new code here +// =============> write your explanation here SyntaxError: Identifier 'str' has already been declared +// =============> write your new code here. + function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} From a729effd278e6664b94739fb0e8e9eca0a21dba3 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Tue, 29 Sep 2026 11:28:18 +0100 Subject: [PATCH 03/27] Fix capitalise function variable redeclaration --- Sprint-3/1-key-errors/0.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 7c0a64325..cc63935bc 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,9 +1,8 @@ // Predict and explain first... // =============> We will have syntax error because string is the parameter of the function and the next line,it is declared wit let -//so it is declared two times in one part +//so it is declared two times in one part // call the function capitalise with a string input - function capitalise(str) { str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; @@ -17,7 +16,7 @@ function capitalise(str) { } // =============> write your explanation here SyntaxError: Identifier 'str' has already been declared -// =============> write your new code here. - function capitalise(str) { +// =============> write your new code here. +function capitalise(str) { return `${str[0].toUpperCase()}${str.slice(1)}`; } From 7cd8ae3cbc5b6a5415d76d2f33d785986d72fc35 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Tue, 29 Sep 2026 12:30:56 +0100 Subject: [PATCH 04/27] fix percentage conversion variable redeclaration --- Sprint-3/1-key-errors/1.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..735e546bf 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -1,7 +1,9 @@ -// Predict and explain first... +// Predict and explain first...:It doesn't run.We have a syntaxError. -// Why will an error occur when this program runs? -// =============> write your prediction here +// Why will an error occur when this program runs?because decimalNumber is declared. +// as a parameter and then declared again using const. + +// =============> write your prediction here:We will have a SyntaxError because decimalNumber is a parameter of the function, but it is declared again using const inside the function. // Try playing computer with the example to work out what is going on @@ -14,7 +16,14 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// =============> write your explanation here:decimalNumber is inside the function, so we can not use it outside the function. // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + ca + return percentage; +} + +console.log(convertToPercentage(0.5)); From a128bbf0c3be5ce748cc877397dac09331039c2f Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Thu, 1 Oct 2026 16:09:54 +0100 Subject: [PATCH 05/27] Fix square function parameter --- Sprint-3/1-key-errors/2.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..9abe6d2e6 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -3,18 +3,23 @@ // 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:We will have a SyntaxError because we need a valid function parameter. function square(3) { return num * num; } -// =============> write the error message here +// =============> write the error message here:SyntaxError: Unexpected number -// =============> explain this error message here +// =============> explain this error message here:function square(3) { +//3 is a number, not a valid variable. Program expects a parameter name there. // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> write your new code here: +function square(num) { + return num * num; +} +console.log(square(3)); From 1d044cbe15112f171f412b4bca88042a986486c9 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Thu, 1 Oct 2026 16:57:31 +0100 Subject: [PATCH 06/27] Fix multiply function to return result --- Sprint-3/2-mandatory-debug/0.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..30b0c5bcd 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,6 +1,7 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: +//The code will run, but the output won't be what we expect because the multiply function logs the result instead of returning it. function multiply(a, b) { console.log(a * b); @@ -8,7 +9,14 @@ 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:console.log(a * b); +//The result is 320, but the function doesn't return a value. It shows us undefined because we don't have return in the function. +//320 +//The result of multiplying 10 and 32 is undefined // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> 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 d1a35bcd17a7544e333cc5a1d055b96cdd931f25 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Thu, 1 Oct 2026 17:38:42 +0100 Subject: [PATCH 07/27] Fix sum function return statement --- Sprint-3/2-mandatory-debug/1.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..e17f83ae6 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here:This is the error:The sum of 10 and 32 is undefined. +// The code will run without a syntax error, but it will return undefined instead of 42. function sum(a, b) { return; @@ -8,6 +9,15 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> write your explanation here: +//The problem is that return; immediately ends the function://return; +//a + b; + +//if we write anything after return(next line)is unreachable, so a + b doesn't run. The function therefore returns undefined. // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); From 35c7d91ba223b082358c9ea8294c12b4cb4d45c2 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Thu, 1 Oct 2026 18:23:47 +0100 Subject: [PATCH 08/27] Fix getLastDigit function parameter --- Sprint-3/2-mandatory-debug/2.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..85b8cdad3 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/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:I predict the output will be 3 every time, because the function uses the global constant num = 103 instead of using the numbers passed into getLastDigit(). const num = 103; @@ -14,11 +14,28 @@ 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 last digit of 42 is 3 +//The last digit of 105 is 3 +//The last digit of 806 is 3 // Explain why the output is the way it is -// =============> write your explanation here +// =============> write your explanation here:there is no parameter in the function. +//So when we call the function: +//getLastDigit(42) +//the 42 is passed to the function, but the function has no parameter to receive it. +//Instead, it uses the global variable (const num = 103) +//so every call converts 103 to a string and gets its last digit: 3. // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> write your new code here: +const num = 103; + +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 2d78dfc6958ea1b38c3909264c29a65a43c159b1 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Thu, 1 Oct 2026 18:34:16 +0100 Subject: [PATCH 09/27] Implement BMI calculation function --- Sprint-3/3-mandatory-implement/1-bmi.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..9c2556516 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -15,5 +15,7 @@ // It should return a string of their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height + const bmi = weight / (height * height); + return bmi.toFixed(1); } +// return the BMI of someone based off their weight and height From 69567327adfde14c94d44612662877f0d3d6ce67 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Thu, 1 Oct 2026 18:47:40 +0100 Subject: [PATCH 10/27] Implement UPPER_SNAKE_CASE conversion function --- Sprint-3/3-mandatory-implement/2-cases.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..91b0012d8 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,9 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase +function toUpperSnakeCase(str) { + return str.replaceAll(" ", "_").toUpperCase(); +} + +console.log(toUpperSnakeCase("hello there")); +console.log(toUpperSnakeCase("lord of the rings")); From 76ac665fd1b241355f1fbaaed0c2df877f4a689f Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Thu, 1 Oct 2026 20:01:42 +0100 Subject: [PATCH 11/27] converting the function into reusable toPounds function --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 4 ++-- Sprint-3/3-mandatory-implement/3-to-pounds.js | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..f47e26f2c 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -2,13 +2,13 @@ const penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, - penceString.length - 1 + penceString.length - 1, ); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); const pounds = paddedPenceNumberString.substring( 0, - paddedPenceNumberString.length - 2 + paddedPenceNumberString.length - 2, ); const pence = paddedPenceNumberString diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..0f94a2cf3 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,27 @@ // 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 penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1, + ); + + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2, + ); + + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + return `£${pounds}.${pence}`; +} + +console.log(toPounds("399p")); +console.log(toPounds("250p")); +console.log(toPounds("99p")); +console.log(toPounds("5p")); From 0b2d01cabe56a37cf80768daf08cffbdf720cd94 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Thu, 1 Oct 2026 20:37:02 +0100 Subject: [PATCH 12/27] writing the answers of formatTimeDisplay function --- Sprint-3/4-mandatory-interpret/time-format.js | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..88f9b2558 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -21,18 +21,41 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> write your answer here: three calls to pad() in the return statement: +//return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; // 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: +//For formatTimeDisplay(61): +//remainingSeconds = 61 % 60 = 1 +//totalMinutes = (61 - 1) / 60 → 1 +//remainingMinutes = 1 % 60 → 1 +//totalHours = (1 - 1) / 60 → 0 +//num = 1 // c) What is the return value of pad when it is called for the first time? -// =============> write your answer here +// =============> write your answer here:num is 0. +//let numString = num.toString(); gives us 0 + +// This loop adds a "0" because the string has only one character: +//numString = "0" + "0"; +//return value is: +//"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 +// =============> write your answer here: +//The last call is: pad(remainingSeconds) + +//For 61 seconds, remainingSeconds is 61 % 60 = 1: +//so num = 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 +// =============> write your answer here: +//num is 1, so: +//num.toString() gives "1". + +// and this loop adds a 0 to the beginning: "01" + +//So the final result of formatTimeDisplay(61) is: 00:01:01 From c287e7c4c144a80fc8e68b263cb67d79ef4166ce Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Tue, 6 Oct 2026 12:11:09 +0100 Subject: [PATCH 13/27] Clean up comments in time-format.js Removed placeholder comments and explanations in time-format.js. --- Sprint-3/4-mandatory-interpret/time-format.js | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index 88f9b2558..c0dd9c9a5 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -21,41 +21,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here: three calls to pad() in the return statement: -//return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; +// =============> write your answer here // 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: -//For formatTimeDisplay(61): -//remainingSeconds = 61 % 60 = 1 -//totalMinutes = (61 - 1) / 60 → 1 -//remainingMinutes = 1 % 60 → 1 -//totalHours = (1 - 1) / 60 → 0 -//num = 1 +// =============> write your answer here // c) What is the return value of pad when it is called for the first time? -// =============> write your answer here:num is 0. -//let numString = num.toString(); gives us 0 - -// This loop adds a "0" because the string has only one character: -//numString = "0" + "0"; -//return value is: -//"00" +// =============> write your answer here // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here: -//The last call is: pad(remainingSeconds) - -//For 61 seconds, remainingSeconds is 61 % 60 = 1: -//so num = 1 +// =============> write your answer here // 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: -//num is 1, so: -//num.toString() gives "1". - -// and this loop adds a 0 to the beginning: "01" - -//So the final result of formatTimeDisplay(61) is: 00:01:01 +// =============> write your answer here From 10d77c63b85686ad7d1c453e41ce6a0bd6894b8a Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Tue, 6 Oct 2026 13:06:45 +0100 Subject: [PATCH 14/27] Enhance comments in time-format.js for clarity Added comments to explain the behavior of the pad function and its calls in formatTimeDisplay. --- Sprint-3/4-mandatory-interpret/time-format.js | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..88f9b2558 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -21,18 +21,41 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> write your answer here: three calls to pad() in the return statement: +//return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; // 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: +//For formatTimeDisplay(61): +//remainingSeconds = 61 % 60 = 1 +//totalMinutes = (61 - 1) / 60 → 1 +//remainingMinutes = 1 % 60 → 1 +//totalHours = (1 - 1) / 60 → 0 +//num = 1 // c) What is the return value of pad when it is called for the first time? -// =============> write your answer here +// =============> write your answer here:num is 0. +//let numString = num.toString(); gives us 0 + +// This loop adds a "0" because the string has only one character: +//numString = "0" + "0"; +//return value is: +//"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 +// =============> write your answer here: +//The last call is: pad(remainingSeconds) + +//For 61 seconds, remainingSeconds is 61 % 60 = 1: +//so num = 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 +// =============> write your answer here: +//num is 1, so: +//num.toString() gives "1". + +// and this loop adds a 0 to the beginning: "01" + +//So the final result of formatTimeDisplay(61) is: 00:01:01 From 54f45d7bc57988d7380835219c3f0c785bca89e1 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Tue, 6 Oct 2026 20:46:21 +0100 Subject: [PATCH 15/27] fix wrong changes --- Sprint-2/1-key-exercises/3-paths.js | 9 ++++---- Sprint-2/2-mandatory-errors/4.js | 5 +++-- .../1-percentage-change.js | 21 +++++++++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..434bd6e8e 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -16,8 +16,9 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable +const dir = filePath.slice(0, lastSlashIndex); +console.log(`The direction of the file is ${dir}`); +const ext = filePath.slice(filePath.lastIndexOf(".") + 1); +console.log(`The extenction of the file is ${ext}`); -const dir = ; -const ext = ; - -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..65111a62c 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,3 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; +// a variable name cannot start with a number and it will cause a SyntaxError diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..2cd1005c3 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -11,12 +11,29 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below -// a) How many function calls are there in this file? Write down all the lines where a function call is made +// a) How many function calls are there in this file? Write down all the lines where a function call is made? +//There are 5 function calls: +//replaceAll +//Line 4 and 5 +//Number(...) +//Line 4 and 5 +//console.log() +//Line 10 , // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +//error:line 5,SyntaxError: missing ) after argument list,there is a missing comma between the two arguments "," and " " // c) Identify all the lines that are variable reassignment statements +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // d) Identify all the lines that are variable declarations +//let carPrice +//let priceAfterOneYear +//const priceDifference +//const percentageChange // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//it removes all commas from the string +//converts the string "10000" into the number 10000 +//The purpose is to turn the price from a formatted string into a number From e9e592eef18c4fba076df37cb58aa7551b99a32a Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:09:39 +0100 Subject: [PATCH 16/27] revert changes --- Sprint-2/1-key-exercises/3-paths.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index 434bd6e8e..433c72934 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -16,9 +16,8 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = filePath.slice(0, lastSlashIndex); -console.log(`The direction of the file is ${dir}`); -const ext = filePath.slice(filePath.lastIndexOf(".") + 1); -console.log(`The extenction of the file is ${ext}`); + +const dir = ; +const ext = ; // https://www.google.com/search?q=slice+mdn From 4815e4cc5003841e6d46b6f5f9677de79d4277c0 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:11:31 +0100 Subject: [PATCH 17/27] revert changes --- Sprint-2/2-mandatory-errors/4.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 65111a62c..5f86c730b 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,3 +1,2 @@ -const twelveHourClockTime = "8:53pm"; -const twentyFourHourClockTime = "20:53"; -// a variable name cannot start with a number and it will cause a SyntaxError +const 12HourClockTime = "8:53pm"; +const 24hourClockTime = "20:53"; From e1c461b2d6e147cc457757c1327e0fe0d07fcdf3 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:12:38 +0100 Subject: [PATCH 18/27] revert changes --- .../1-percentage-change.js | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index 2cd1005c3..e24ecb8e1 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -11,29 +11,12 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below -// a) How many function calls are there in this file? Write down all the lines where a function call is made? -//There are 5 function calls: -//replaceAll -//Line 4 and 5 -//Number(...) -//Line 4 and 5 -//console.log() -//Line 10 , +// a) How many function calls are there in this file? Write down all the lines where a function call is made // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? -//error:line 5,SyntaxError: missing ) after argument list,there is a missing comma between the two arguments "," and " " // c) Identify all the lines that are variable reassignment statements -//carPrice = Number(carPrice.replaceAll(",", "")); -//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // d) Identify all the lines that are variable declarations -//let carPrice -//let priceAfterOneYear -//const priceDifference -//const percentageChange // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -//it removes all commas from the string -//converts the string "10000" into the number 10000 -//The purpose is to turn the price from a formatted string into a number From 7a13accf5215fa7e94d09c528078532ab874fe5d Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:17:45 +0100 Subject: [PATCH 19/27] revert changes Removed duplicate comment and fixed typo. --- Sprint-2/1-key-exercises/1-count.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index bf906426d..117bcb2b6 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -3,5 +3,4 @@ let count = 0; count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe whaWt line 3 is doing, in particular focus on what = is doing // Describe what line 3 is doing, in particular focus on what = is doing From fd9940e2b84856b6a8f1894aa58604880379b90a Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:19:43 +0100 Subject: [PATCH 20/27] revert changes From fa1b84beb739e11249546ded8823b511b53cb8eb Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:21:10 +0100 Subject: [PATCH 21/27] Fix syntax errors in paths.js --- Sprint-2/1-key-exercises/3-paths.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index 433c72934..f93e7f69a 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -21,3 +21,4 @@ const dir = ; const ext = ; // https://www.google.com/search?q=slice+mdn + From 37ef650b6f5274bc521cf8b69eb2b62b70b0765d Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:21:36 +0100 Subject: [PATCH 22/27] Remove empty variable assignments in paths.js --- Sprint-2/1-key-exercises/3-paths.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index f93e7f69a..433c72934 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -21,4 +21,3 @@ const dir = ; const ext = ; // https://www.google.com/search?q=slice+mdn - From f98fb5e1ed7b81d4f4ba953e955e29184d20120e Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:22:18 +0100 Subject: [PATCH 23/27] revert changes From 2adce383af81e2f960fadd7169bbf9705369a063 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:22:58 +0100 Subject: [PATCH 24/27] Delete Sprint-2/1-key-exercises/3-paths.js --- Sprint-2/1-key-exercises/3-paths.js | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 Sprint-2/1-key-exercises/3-paths.js diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js deleted file mode 100644 index 433c72934..000000000 --- a/Sprint-2/1-key-exercises/3-paths.js +++ /dev/null @@ -1,23 +0,0 @@ -// The diagram below shows the different names for parts of a file path on a Unix operating system - -// ┌─────────────────────┬────────────┐ -// │ dir │ base │ -// ├──────┬ ├──────┬─────┤ -// │ root │ │ name │ ext │ -// " / home/user/dir / file .txt " -// └──────┴──────────────┴──────┴─────┘ - -// (All spaces in the "" line should be ignored. They are purely for formatting.) - -const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -const lastSlashIndex = filePath.lastIndexOf("/"); -const base = filePath.slice(lastSlashIndex + 1); -console.log(`The base part of ${filePath} is ${base}`); - -// Create a variable to store the dir part of the filePath variable -// Create a variable to store the ext part of the variable - -const dir = ; -const ext = ; - -// https://www.google.com/search?q=slice+mdn From fa4e2909a3f3929bb5b59ceb50cb5c1b66f97b57 Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:23:37 +0100 Subject: [PATCH 25/27] Add files via upload --- Sprint-2/1-key-exercises/3-paths.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Sprint-2/1-key-exercises/3-paths.js diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js new file mode 100644 index 000000000..ab90ebb28 --- /dev/null +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -0,0 +1,23 @@ +// The diagram below shows the different names for parts of a file path on a Unix operating system + +// ┌─────────────────────┬────────────┐ +// │ dir │ base │ +// ├──────┬ ├──────┬─────┤ +// │ root │ │ name │ ext │ +// " / home/user/dir / file .txt " +// └──────┴──────────────┴──────┴─────┘ + +// (All spaces in the "" line should be ignored. They are purely for formatting.) + +const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; +const lastSlashIndex = filePath.lastIndexOf("/"); +const base = filePath.slice(lastSlashIndex + 1); +console.log(`The base part of ${filePath} is ${base}`); + +// Create a variable to store the dir part of the filePath variable +// Create a variable to store the ext part of the variable + +const dir = ; +const ext = ; + +// https://www.google.com/search?q=slice+mdn \ No newline at end of file From 91bfb827bc106ae89cfaeb70472c2f2cc857fcaa Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:24:46 +0100 Subject: [PATCH 26/27] Delete Sprint-2/3-mandatory-interpret/3-to-pounds.js --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 Sprint-2/3-mandatory-interpret/3-to-pounds.js diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js deleted file mode 100644 index f47e26f2c..000000000 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ /dev/null @@ -1,27 +0,0 @@ -const penceString = "399p"; - -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1, -); - -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2, -); - -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); - -console.log(`£${pounds}.${pence}`); - -// This program takes a string representing a price in pence -// The program then builds up a string representing the price in pounds - -// You need to do a step-by-step breakdown of each line in this program -// Try and describe the purpose / rationale behind each step - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" From 64e95e74bc061971a2c24d7a6005d4938d814cba Mon Sep 17 00:00:00 2001 From: anitahy73 Date: Sun, 11 Oct 2026 18:25:14 +0100 Subject: [PATCH 27/27] Add files via upload --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Sprint-2/3-mandatory-interpret/3-to-pounds.js diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js new file mode 100644 index 000000000..60c9ace69 --- /dev/null +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -0,0 +1,27 @@ +const penceString = "399p"; + +const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 +); + +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 +); + +const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + +console.log(`£${pounds}.${pence}`); + +// This program takes a string representing a price in pence +// The program then builds up a string representing the price in pounds + +// You need to do a step-by-step breakdown of each line in this program +// Try and describe the purpose / rationale behind each step + +// To begin, we can start with +// 1. const penceString = "399p": initialises a string variable with the value "399p"