From 2dd0a787c40f47f15b8439778049e06fba3f58d6 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Tue, 17 Jun 2025 23:30:18 +0100 Subject: [PATCH 01/25] explain Increment count variable by 1 after initialization. --- Sprint-1/1-key-exercises/1-count.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..91605a33e 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,6 @@ let count = 0; count = count + 1; +// // Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe what line 3 is doing, in particular focus on what = is doing +// Line 3 Take the current value of count, and then add 1, and store the result back in count . \ No newline at end of file From 1bc5c74bcbf970addc25aa0dc885f2d2c4527f7e Mon Sep 17 00:00:00 2001 From: Samiuk Date: Tue, 17 Jun 2025 23:33:40 +0100 Subject: [PATCH 02/25] Create initials variable by extracting first characters of first, middle, and last names. --- Sprint-1/1-key-exercises/2-initials.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..538997ca1 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,11 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -let initials = ``; + +let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0); + +console.log(initials); + // https://www.google.com/search?q=get+first+character+of+string+mdn From b16d04875b0aa045deabd421de33a78d83c63192 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Tue, 17 Jun 2025 23:36:19 +0100 Subject: [PATCH 03/25] create two variable and Extract directory and file extension parts from file path string using slice. --- Sprint-1/1-key-exercises/3-paths.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..4daa0d8d9 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,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 = ; -const ext = ; +const dir = filePath.slice(0, lastSlashIndex); +const ext = base.slice(base.lastIndexOf(".") + 1); + // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 625c1142588d533ec5988676624ed6e3f82bbfd6 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Tue, 17 Jun 2025 23:39:18 +0100 Subject: [PATCH 04/25] Add comments explaining how num is calculated as a random integer between minimum and maximum. --- Sprint-1/1-key-exercises/4-random.js | 75 ++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..04a0e0a07 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -3,7 +3,74 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; -// In this exercise, you will need to work out what num represents? -// Try breaking down the expression and using documentation to explain what it means -// It will help to think about the order in which expressions are evaluated -// Try logging the value of num and running the program several times to build an idea of what the program is doing +// 1- In this exercise, you will need to work out what num represents? + +// the num gives a random whole number between 1 and 100 like 73, 12, or 100. + +// 2- Try breaking down the expression and using documentation to explain what it means +/* + +1. Math.random() + +Returns a random decimal number between 0 and 1 but never gives 1.0. + +Example: 0.24 + +2. (maximum - minimum + 1) + +This gives number of possible values. + +Without the +1, we'd only get the difference, not the full count. + +for example: + +5 - 1 = 4 → but there are actually 5 numbers: 1, 2, 3, 4, 5 + +So we add +1 to include both ends of the range. + +3. Math.random() * (maximum - minimum + 1) + +This gives a random decimal number between 0 and 100 (like 24, 65 ...) + +Because we want the random decimal scaled to the size of the range of possible values. + +For example, if we want a number between 1 and 100 (inclusive), there are 100 possible numbers (1, 2, ..., 100). + +Multiplying by 100 means the decimal is scaled up to cover all those possibilities before rounding. + +4. Math.floor(...) + +This rounds the decimal down to the nearest whole number. + +Example: Math.floor(78.43) → 78 + +5. + minimum + +we add the minimum to shift the range correctly, and make sure the random number up to start from minimum. + +5-1- for example if we remove the + minimum + +5-1-1 Math.random() 0.9999 * 99 + 1 → only goes up to 99.999... → max = 99.999... → floor = 100 (but very unlikely) + +now 100 becomes very hard to reach, and in many cases, you never get it. + +5-1-2 Math.random() 0.00 * 99 + 1 → only goes up to 0... → max = 0... → floor = 0 (now the minimum is 0, and can appears) + +conclusion : when we don’t add + minimum, there is a chance that 1 appears, but it’s not the guaranteed minimum anymore — + +and the range starts at 0, not 1. + +5-2- when we add +minimum + +now we make sure the min and max can appear in the final results and make sure the minimum is 1 not 0. + +Minimum appears when random = 0 + +Maximum appears when random is almost 1 (like 0.9999...). + +example : Math.random() * 99 + 1 → up to 0.99 → max = 99 → floor = 99 → +1 = 100 (so more possibilities for 100 to appears) + +*/ + +//It will help to think about the order in which expressions are evaluated +//Try logging the value of num and running the program several times to build an idea of what the program is doing From f5522e711f8c7c8e93631c8cf4bce1b964409cff Mon Sep 17 00:00:00 2001 From: Samiuk Date: Tue, 17 Jun 2025 23:41:09 +0100 Subject: [PATCH 05/25] Add explanation for incrementing count variable by 1 after initialization. --- Sprint-1/1-key-exercises/1-count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 91605a33e..dfb02c25f 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,4 @@ count = count + 1; // // Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Line 3 Take the current value of count, and then add 1, and store the result back in count . \ No newline at end of file +// Line 3 Take the current value of count, and then add 1, and store the result back in count. \ No newline at end of file From 2f17199bc2c0f56768b6eaa43ff304d79ad64c8e Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 07:29:00 +0100 Subject: [PATCH 06/25] Update 0.js Added comments to exclude instructional lines from execution. --- Sprint-1/2-mandatory-errors/0.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..2dd55b437 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,12 @@ + // we can turn the lines into comments. we can use: + +// for single-line comments, or + +/* for multi-line comments. */ + +/* + This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +We don't want the computer to run these 2 lines - how can we solve this problem? + +*/ From 5e31d7c8bf1b57d4057959248d567ef3f0bf47c5 Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 07:32:14 +0100 Subject: [PATCH 07/25] Update 1.js Updated age variable to let to allow incrementing its value --- Sprint-1/2-mandatory-errors/1.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..95b871f27 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 +// Changed age declaration from const to let to allow reassignment -const age = 33; +let age = 33; age = age + 1; From 5cf1cfd00d3a1419825f6ccef5d8fcdf55029cb5 Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 07:35:26 +0100 Subject: [PATCH 08/25] Update 2.js Declare variable before using in template string. --- Sprint-1/2-mandatory-errors/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..3c58edaf8 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,5 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... -// what's the error ? +// what's the error ? The error here is due to using a variable before it's declared. console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; From 2d1e8dd2f6ac80695c98e9e1607f2208a929c1e5 Mon Sep 17 00:00:00 2001 From: HoussamLh <156331030+HoussamLh@users.noreply.github.com> Date: Thu, 19 Jun 2025 07:45:10 +0100 Subject: [PATCH 09/25] Update 3.js Add comments explaining slice error and fix by converting number to string --- Sprint-1/2-mandatory-errors/3.js | 41 +++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..16450f64d 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,34 @@ +// We want last4Digits to store the last 4 digits of cardNumber + +/* + Prediction before running: + This will cause an error because cardNumber is a number, + and numbers don't have the slice() method. slice() works only on strings or arrays. + +*/ + +/* + Running the code would give: + TypeError: cardNumber.slice is not a function. + +*/ + +/* + Why? + Because slice() is not defined for numbers in JavaScript. + +*/ + +/* + Fix: + Convert cardNumber to a string first, so we can use slice() on it. + Then slice the last 4 characters to get the last 4 digits. + +*/ + const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); - -// The last4Digits variable should store the last 4 digits of cardNumber -// However, the code isn't working -// Before running the code, make and explain a prediction about why the code won't work -// Then run the code and see what error it gives. -// Consider: Why does it give this error? Is this what I predicted? If not, what's different? -// Then try updating the expression last4Digits is assigned to, in order to get the correct value + +const last4Digits = String(cardNumber).slice(-4); + +console.log(last4Digits); // Output: 4213 + From 4723bb91326e21e0c0bacbcd7d94ec7338d9536d Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 20 Jul 2025 21:14:36 +0100 Subject: [PATCH 10/25] implement getAngleType function with all angle cases and tests --- Sprint-3/1-key-implement/1-get-angle-type.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 08d1f0cba..1447f1e30 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -8,8 +8,11 @@ // Then, write the next test! :) Go through this process until all the cases are implemented function getAngleType(angle) { - if (angle === 90) return "Right angle"; - // read to the end, complete line 36, then pass your test here + if (angle === 90) return "Right angle"; + if (angle < 90) return "Acute angle"; + if (angle > 90 && angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + if (angle > 180 && angle < 360) return "Reflex angle"; } // we're going to use this helper function to make our assertions easier to read @@ -39,18 +42,23 @@ assertEquals(right, "Right angle"); const acute = getAngleType(45); assertEquals(acute, "Acute angle"); + // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" const obtuse = getAngleType(120); -// ====> write your test here, and then add a line to pass the test in the function above +assertEquals(obtuse, "Obtuse angle"); + // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" -// ====> write your test here, and then add a line to pass the test in the function above +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" -// ====> write your test here, and then add a line to pass the test in the function above \ No newline at end of file +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); From 85a7125dc0070e3e9bfe36c36229b49c985c4e2e Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 20 Jul 2025 21:22:23 +0100 Subject: [PATCH 11/25] implement isProperFraction with tests for positive, negative, equal numerator cases and add stretch scenarios for isProperFraction edge case testing --- .../1-key-implement/2-is-proper-fraction.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-implement/2-is-proper-fraction.js b/Sprint-3/1-key-implement/2-is-proper-fraction.js index 91583e941..82c0520d2 100644 --- a/Sprint-3/1-key-implement/2-is-proper-fraction.js +++ b/Sprint-3/1-key-implement/2-is-proper-fraction.js @@ -8,7 +8,9 @@ // write one test at a time, and make it pass, build your solution up methodically function isProperFraction(numerator, denominator) { + // Use absolute value of numerator to handle negatives if (numerator < denominator) return true; + return false; // for all other cases } // here's our helper again @@ -40,14 +42,28 @@ assertEquals(improperFraction, false); // target output: true // Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. const negativeFraction = isProperFraction(-4, 7); -// ====> complete with your assertion +assertEquals(negativeFraction, true); // Equal Numerator and Denominator check: // Input: numerator = 3, denominator = 3 // target output: false // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. const equalFraction = isProperFraction(3, 3); -// ====> complete with your assertion +assertEquals(equalFraction, false); // Stretch: // What other scenarios could you test for? + +// Other scenarios to test could include: + +// Cases where the numerator or denominator is zero (e.g., 0/5, 5/0) — +// especially to check for division by zero or invalid fractions. + +// Fractions with negative denominators (e.g., 3/-4) +// to see if the function handles sign correctly. + +// Very large numbers +// to check if the function works with large integers. + +// Non-integer inputs (e.g., decimals or strings) +// to test input validation (if applicable). \ No newline at end of file From a6dd8840432c55caf5473943552e2395e9b214f1 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 20 Jul 2025 21:36:06 +0100 Subject: [PATCH 12/25] Implement getCardValue to return correct blackjack values for all valid cards and throw error for invalid ones --- Sprint-3/1-key-implement/3-get-card-value.js | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index aa1cc9f90..43002d485 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -8,7 +8,12 @@ // write one test at a time, and make it pass, build your solution up methodically // just make one change at a time -- don't rush -- programmers are deep and careful thinkers function getCardValue(card) { - if (rank === "A") return 11; + const rank = card.slice(0, -1); // remove the emoji + if (rank === "A") return 11; + if (["K", "Q", "J", "10"].includes(rank)) return 10; + const number = Number(rank); + if (number >= 2 && number <= 9) return number; + throw new Error("Invalid card rank"); } // You need to write assertions for your function to check it works in different cases @@ -33,19 +38,36 @@ assertEquals(aceofSpades, 11); // When the function is called with such a card, // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). const fiveofHearts = getCardValue("5♥"); -// ====> write your test here, and then add a line to pass the test in the function above +assertEquals(fiveofHearts, 5); + // Handle Face Cards (J, Q, K): // Given a card with a rank of "10," "J," "Q," or "K", // When the function is called with such a card, // Then it should return the value 10, as these cards are worth 10 points each in blackjack. +const jackofClubs = getCardValue("J♣"); +assertEquals(jackofClubs, 10); + +const queenofDiamonds = getCardValue("Q♦"); +assertEquals(queenofDiamonds, 10); + +const kingofHearts = getCardValue("K♥"); +assertEquals(kingofHearts, 10); // Handle Ace (A): // Given a card with a rank of "A", // When the function is called with an Ace, // Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. +const aceofSpades = getCardValue("A♠"); +assertEquals(aceofSpades, 11); + // Handle Invalid Cards: // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." + + +// getCardValue("Z♠"); // should throw "Invalid card rank" + + From cb53f9aec085c07b58d360f49d5b5974f74767f6 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 20 Jul 2025 21:41:41 +0100 Subject: [PATCH 13/25] Export complete getAngleType() function for Jest testing --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index d61254bd7..e7a3e28ee 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -1,7 +1,10 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; - // replace with your completed function from key-implement - + if (angle < 90) return "Acute angle"; + if (angle > 90 && angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + if (angle > 180 && angle < 360) return "Reflex angle"; + throw new Error("Invalid angle"); } @@ -11,8 +14,10 @@ function getAngleType(angle) { + // Don't get bogged down in this detail // Jest uses CommonJS module syntax by default as it's quite old // We will upgrade our approach to ES6 modules in the next course module, so for now // we have just written the CommonJS module.exports syntax for you + module.exports = getAngleType; \ No newline at end of file From 5a07227d8ecda8d9d84bd407cce9427ca5755b38 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 20 Jul 2025 21:43:06 +0100 Subject: [PATCH 14/25] Add Jest tests for all angle types in getAngleType() --- .../1-get-angle-type.test.js | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index b62827b7c..c3a35db8e 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -4,21 +4,19 @@ test("should identify right angle (90°)", () => { expect(getAngleType(90)).toEqual("Right angle"); }); -// REPLACE the comments with the tests -// make your test descriptions as clear and readable as possible +test("should identify acute angle (< 90°)", () => { + expect(getAngleType(45)).toEqual("Acute angle"); +}); -// Case 2: Identify Acute Angles: -// When the angle is less than 90 degrees, -// Then the function should return "Acute angle" +test("should identify obtuse angle (> 90° and < 180°)", () => { + expect(getAngleType(120)).toEqual("Obtuse angle"); +}); -// Case 3: Identify Obtuse Angles: -// When the angle is greater than 90 degrees and less than 180 degrees, -// Then the function should return "Obtuse angle" +test("should identify straight angle (180°)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); -// Case 4: Identify Straight Angles: -// When the angle is exactly 180 degrees, -// Then the function should return "Straight angle" +test("should identify reflex angle (> 180° and < 360°)", () => { + expect(getAngleType(270)).toEqual("Reflex angle"); +}); -// Case 5: Identify Reflex Angles: -// When the angle is greater than 180 degrees and less than 360 degrees, -// Then the function should return "Reflex angle" From a417fa0b5a6d196fd485de7cc8de677e75b37155 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 20 Jul 2025 21:46:09 +0100 Subject: [PATCH 15/25] Implement isProperFraction to handle proper, improper, and negative fractions --- .../2-mandatory-rewrite/2-is-proper-fraction.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 9836fe398..9305566fa 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,6 +1,15 @@ +// Explanation: +// It checks if the absolute value of the numerator +// is less than the absolute value of the denominator. + + function isProperFraction(numerator, denominator) { - if (numerator < denominator) return true; - // add your completed function from key-implement here + if (denominator === 0) { + throw new Error("Denominator cannot be zero"); + } + + return Math.abs(numerator) < Math.abs(denominator); } -module.exports = isProperFraction; \ No newline at end of file +module.exports = isProperFraction; + From 461d0b68a6b1ebccfb31fd8d37edd1b1e7f712d9 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 20 Jul 2025 21:47:41 +0100 Subject: [PATCH 16/25] Add unit tests for isProperFraction covering all key scenarios --- .../2-mandatory-rewrite/2-is-proper-fraction.test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index ff1cc8173..7032715dc 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -5,7 +5,16 @@ test("should return true for a proper fraction", () => { }); // Case 2: Identify Improper Fractions: +test("should return false for an improper fraction", () => { + expect(isProperFraction(5, 2)).toEqual(false); +}); // Case 3: Identify Negative Fractions: +test("should return true for a negative proper fraction", () => { + expect(isProperFraction(-4, 7)).toEqual(true); +}); // Case 4: Identify Equal Numerator and Denominator: +test("should return false when numerator equals denominator", () => { + expect(isProperFraction(3, 3)).toEqual(false); +}); From 057740bf78fb903ccf8cdb9475d090dd192aa8d6 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 20 Jul 2025 21:51:42 +0100 Subject: [PATCH 17/25] Implement getCardValue function with support for number, face, and ace cards; throw error for invalid cards --- Sprint-3/2-mandatory-rewrite/3-get-card-value.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 0d95d3736..e870ce006 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,5 +1,15 @@ function getCardValue(card) { - // replace with your code from key-implement - return 11; + const rank = card.slice(0, -1); // All characters except the last one (suit) + + if (!rank) throw new Error("Invalid card rank"); + + if (rank === "A") return 11; + if (["K", "Q", "J", "10"].includes(rank)) return 10; + + const number = Number(rank); + if (number >= 2 && number <= 9) return number; + + throw new Error("Invalid card rank"); } -module.exports = getCardValue; \ No newline at end of file + +module.exports = getCardValue; From 48444efb4406d4fd080c3d6480292d7cfa148847 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Sun, 20 Jul 2025 21:53:08 +0100 Subject: [PATCH 18/25] Add tests for getCardValue covering number cards, face cards, and invalid input --- .../3-get-card-value.test.js | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 03a8e2f34..463380642 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -1,11 +1,33 @@ const getCardValue = require("./3-get-card-value"); test("should return 11 for Ace of Spades", () => { - const aceofSpades = getCardValue("A♠"); - expect(aceofSpades).toEqual(11); - }); - -// Case 2: Handle Number Cards (2-10): -// Case 3: Handle Face Cards (J, Q, K): -// Case 4: Handle Ace (A): -// Case 5: Handle Invalid Cards: + expect(getCardValue("A♠")).toEqual(11); +}); + +// Case 2: Handle Number Cards (2-10) +test("should return 5 for Five of Hearts", () => { + expect(getCardValue("5♥")).toEqual(5); +}); + +test("should return 10 for Ten of Diamonds", () => { + expect(getCardValue("10♦")).toEqual(10); +}); + +// Case 3: Handle Face Cards (J, Q, K) +test("should return 10 for Jack of Clubs", () => { + expect(getCardValue("J♣")).toEqual(10); +}); + +test("should return 10 for Queen of Spades", () => { + expect(getCardValue("Q♠")).toEqual(10); +}); + +test("should return 10 for King of Hearts", () => { + expect(getCardValue("K♥")).toEqual(10); +}); + +// Case 5: Handle Invalid Cards +test("should throw an error for invalid card rank", () => { + expect(() => getCardValue("Z♣")).toThrow("Invalid card rank"); +}); + From 633a7af7c501a14aaad17448fb7ce462a97a832a Mon Sep 17 00:00:00 2001 From: Samiuk Date: Mon, 21 Jul 2025 19:27:34 +0100 Subject: [PATCH 19/25] Revert Sprint-1 folder to CYF's original version --- Sprint-1/1-key-exercises/1-count.js | 3 +- Sprint-1/1-key-exercises/2-initials.js | 6 +-- Sprint-1/1-key-exercises/3-paths.js | 5 +- Sprint-1/1-key-exercises/4-random.js | 75 ++------------------------ Sprint-1/2-mandatory-errors/0.js | 12 +---- Sprint-1/2-mandatory-errors/1.js | 3 +- Sprint-1/2-mandatory-errors/2.js | 2 +- Sprint-1/2-mandatory-errors/3.js | 41 +++----------- 8 files changed, 19 insertions(+), 128 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index dfb02c25f..117bcb2b6 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,6 +2,5 @@ let count = 0; count = count + 1; -// // Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Line 3 Take the current value of count, and then add 1, and store the result back in count. \ No newline at end of file +// Describe what line 3 is doing, in particular focus on what = is doing diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 538997ca1..47561f617 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,11 +5,7 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. - -let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0); - -console.log(initials); - +let initials = ``; // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 4daa0d8d9..ab90ebb28 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,8 +17,7 @@ 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); -const ext = base.slice(base.lastIndexOf(".") + 1); - +const dir = ; +const ext = ; // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 04a0e0a07..292f83aab 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -3,74 +3,7 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; -// 1- In this exercise, you will need to work out what num represents? - -// the num gives a random whole number between 1 and 100 like 73, 12, or 100. - -// 2- Try breaking down the expression and using documentation to explain what it means -/* - -1. Math.random() - -Returns a random decimal number between 0 and 1 but never gives 1.0. - -Example: 0.24 - -2. (maximum - minimum + 1) - -This gives number of possible values. - -Without the +1, we'd only get the difference, not the full count. - -for example: - -5 - 1 = 4 → but there are actually 5 numbers: 1, 2, 3, 4, 5 - -So we add +1 to include both ends of the range. - -3. Math.random() * (maximum - minimum + 1) - -This gives a random decimal number between 0 and 100 (like 24, 65 ...) - -Because we want the random decimal scaled to the size of the range of possible values. - -For example, if we want a number between 1 and 100 (inclusive), there are 100 possible numbers (1, 2, ..., 100). - -Multiplying by 100 means the decimal is scaled up to cover all those possibilities before rounding. - -4. Math.floor(...) - -This rounds the decimal down to the nearest whole number. - -Example: Math.floor(78.43) → 78 - -5. + minimum - -we add the minimum to shift the range correctly, and make sure the random number up to start from minimum. - -5-1- for example if we remove the + minimum - -5-1-1 Math.random() 0.9999 * 99 + 1 → only goes up to 99.999... → max = 99.999... → floor = 100 (but very unlikely) - -now 100 becomes very hard to reach, and in many cases, you never get it. - -5-1-2 Math.random() 0.00 * 99 + 1 → only goes up to 0... → max = 0... → floor = 0 (now the minimum is 0, and can appears) - -conclusion : when we don’t add + minimum, there is a chance that 1 appears, but it’s not the guaranteed minimum anymore — - -and the range starts at 0, not 1. - -5-2- when we add +minimum - -now we make sure the min and max can appear in the final results and make sure the minimum is 1 not 0. - -Minimum appears when random = 0 - -Maximum appears when random is almost 1 (like 0.9999...). - -example : Math.random() * 99 + 1 → up to 0.99 → max = 99 → floor = 99 → +1 = 100 (so more possibilities for 100 to appears) - -*/ - -//It will help to think about the order in which expressions are evaluated -//Try logging the value of num and running the program several times to build an idea of what the program is doing +// In this exercise, you will need to work out what num represents? +// Try breaking down the expression and using documentation to explain what it means +// It will help to think about the order in which expressions are evaluated +// Try logging the value of num and running the program several times to build an idea of what the program is doing diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index 2dd55b437..cf6c5039f 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,12 +1,2 @@ - // we can turn the lines into comments. we can use: - -// for single-line comments, or - -/* for multi-line comments. */ - -/* - This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? - -*/ +We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 95b871f27..7a43cbea7 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,5 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -// Changed age declaration from const to let to allow reassignment -let age = 33; +const age = 33; age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index 3c58edaf8..e09b89831 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,5 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... -// what's the error ? The error here is due to using a variable before it's declared. +// what's the error ? console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 16450f64d..ec101884d 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,34 +1,9 @@ -// We want last4Digits to store the last 4 digits of cardNumber - -/* - Prediction before running: - This will cause an error because cardNumber is a number, - and numbers don't have the slice() method. slice() works only on strings or arrays. - -*/ - -/* - Running the code would give: - TypeError: cardNumber.slice is not a function. - -*/ - -/* - Why? - Because slice() is not defined for numbers in JavaScript. - -*/ - -/* - Fix: - Convert cardNumber to a string first, so we can use slice() on it. - Then slice the last 4 characters to get the last 4 digits. - -*/ - const cardNumber = 4533787178994213; - -const last4Digits = String(cardNumber).slice(-4); - -console.log(last4Digits); // Output: 4213 - +const last4Digits = cardNumber.slice(-4); + +// The last4Digits variable should store the last 4 digits of cardNumber +// However, the code isn't working +// Before running the code, make and explain a prediction about why the code won't work +// Then run the code and see what error it gives. +// Consider: Why does it give this error? Is this what I predicted? If not, what's different? +// Then try updating the expression last4Digits is assigned to, in order to get the correct value From 6d8d7bba46ed3b6060ca307148e6d6a8cafdea69 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Mon, 21 Jul 2025 20:10:05 +0100 Subject: [PATCH 20/25] Implement countChar function to count occurrences of a character in a string --- Sprint-3/3-mandatory-practice/implement/count.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index fce249650..189cdd7c6 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -1,5 +1,11 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (let char of stringOfCharacters) { + if (char === findCharacter) { + count++; + } + } + return count; } module.exports = countChar; \ No newline at end of file From 50eaeb46db5e8f7d43be7486581ce8e8b4188a0a Mon Sep 17 00:00:00 2001 From: Samiuk Date: Mon, 21 Jul 2025 20:13:40 +0100 Subject: [PATCH 21/25] Implement getOrdinalNumber to handle ordinal suffixes correctly - Return proper suffixes for 1st, 2nd, 3rd, and others (e.g., 4th, 11th, 23rd) - Added Jest tests for various edge cases including teens (11th-13th) - Improved function to handle general inputs dynamically --- .../implement/get-ordinal-number.js | 11 +++++++++-- .../implement/get-ordinal-number.test.js | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 24f528b0d..a9af31a01 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -1,5 +1,12 @@ function getOrdinalNumber(num) { - return "1st"; + const suffixes = ["th", "st", "nd", "rd"]; + const value = num % 100; + if (value >= 11 && value <= 13) { + return num + "th"; + } + const lastDigit = num % 10; + const suffix = suffixes[lastDigit] || "th"; + return num + suffix; } -module.exports = getOrdinalNumber; \ No newline at end of file +module.exports = getOrdinalNumber; diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 6d55dfbb4..f35c237bb 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -11,3 +11,20 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); + +test("should return '2nd' for 2", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); +}); + +test("should return '3rd' for 3", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); +}); + +test("should return '4th' for 4", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); +}); + +test("should return '11th' for 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); +}); + From e2c7e37ff30fd1e18a3312614e1510be3eabb588 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Mon, 21 Jul 2025 20:20:38 +0100 Subject: [PATCH 22/25] Implement repeat function with parameters and error handling - Added str and count parameters to repeat function - Used String.repeat to repeat str count times - Throws error if count is negative - Added tests for count = 1, 0, and negative values --- .../3-mandatory-practice/implement/repeat.js | 9 ++++-- .../implement/repeat.test.js | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 621f9bd35..82c4a1edf 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -1,5 +1,8 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, count) { + if (count < 0) { + throw new Error("Count must be non-negative"); + } + return str.repeat(count); } -module.exports = repeat; \ No newline at end of file +module.exports = repeat; diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 8a4ab42ef..facc0f327 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -16,17 +16,46 @@ test("should repeat the string count times", () => { expect(repeatedStr).toEqual("hellohellohello"); }); + const repeat = require("./repeat"); + +// test("should repeat the string count times", () => { +// expect(repeat("hello", 3)).toEqual("hellohellohello"); +// }); + // case: handle Count of 1: // Given a target string str and a count equal to 1, // When the repeat function is called with these inputs, // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. +test("should return original string when count is 1", () => { + expect(repeat("hello", 1)).toEqual("hello"); +}); + + // case: Handle Count of 0: // Given a target string str and a count equal to 0, // When the repeat function is called with these inputs, // Then it should return an empty string, ensuring that a count of 0 results in an empty output. +test("should return empty string when count is 0", () => { + expect(repeat("hello", 0)).toEqual(""); +}); + // case: Negative Count: // Given a target string str and a negative integer count, // When the repeat function is called with these inputs, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. + +test("should throw error for negative count", () => { + expect(() => repeat("hello", -1)).toThrow("Count must be non-negative"); +}); + + + + + + + + + + From 276c348bdb24e435f309c1289f640ac9d4f08f0e Mon Sep 17 00:00:00 2001 From: Samiuk Date: Mon, 21 Jul 2025 20:37:04 +0100 Subject: [PATCH 23/25] Implement find function to locate character index in string with detailed comments and explanations --- Sprint-3/4-stretch-investigate/find.js | 32 ++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Sprint-3/4-stretch-investigate/find.js b/Sprint-3/4-stretch-investigate/find.js index c7e79a2f2..55bb4d848 100644 --- a/Sprint-3/4-stretch-investigate/find.js +++ b/Sprint-3/4-stretch-investigate/find.js @@ -1,25 +1,33 @@ function find(str, char) { + // Start searching from the first character (index 0) let index = 0; + // Continue looping while index is less than the length of the string + // This prevents us from going beyond the last character of the string while (index < str.length) { + // Check if the current character matches the one we are looking for if (str[index] === char) { + // If found, return the current index position return index; } - index++; + // Move to the next character in the string + index++; // This increments index by 1, so the loop moves through each character } + + // If we finish the loop without finding the character, return -1 + // This means the character does not exist in the string return -1; } -console.log(find("code your future", "u")); -console.log(find("code your future", "z")); - -// The while loop statement allows us to do iteration - the repetition of a certain number of tasks according to some condition -// See the docs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while +// Test examples: +console.log(find("code your future", "u")); // Should output the first index of 'u' +console.log(find("code your future", "z")); // Should output -1 since 'z' is not in the string -// Use the Python Visualiser to help you play computer with this example and observe how this code is executed -// Pay particular attention to the following: +/* +Explanation: +a) The 'index' variable starts at 0 and increments by 1 each loop (index++), allowing the function to check each character in the string. +b) The 'if' statement checks whether the current character (str[index]) matches the character we're searching for. +c) 'index++' is used to move forward to the next character in the string on each loop iteration. +d) The condition 'index < str.length' ensures the loop only runs while 'index' is a valid position inside the string, preventing errors. +*/ -// a) How the index variable updates during the call to find -// b) What is the if statement used to check -// c) Why is index++ being used? -// d) What is the condition index < str.length used for? From 28dfefd0ebcd9669a5e5eb5ec2805ab9d6073031 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Mon, 21 Jul 2025 20:39:21 +0100 Subject: [PATCH 24/25] just to writing a missing bits. --- Sprint-3/4-stretch-investigate/find.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-3/4-stretch-investigate/find.js b/Sprint-3/4-stretch-investigate/find.js index 55bb4d848..aebe1ca90 100644 --- a/Sprint-3/4-stretch-investigate/find.js +++ b/Sprint-3/4-stretch-investigate/find.js @@ -25,9 +25,11 @@ console.log(find("code your future", "z")); // Should output -1 since 'z' is not /* Explanation: -a) The 'index' variable starts at 0 and increments by 1 each loop (index++), allowing the function to check each character in the string. +a) The 'index' variable starts at 0 and increments by 1 each loop (index++), allowing the function to +check each character in the string. b) The 'if' statement checks whether the current character (str[index]) matches the character we're searching for. c) 'index++' is used to move forward to the next character in the string on each loop iteration. -d) The condition 'index < str.length' ensures the loop only runs while 'index' is a valid position inside the string, preventing errors. +d) The condition 'index < str.length' ensures the loop only runs while 'index' is a valid position inside the string, +preventing errors. */ From c3ed0d1e0d2e9c2865778564c6a4485bc52b287d Mon Sep 17 00:00:00 2001 From: Samiuk Date: Mon, 21 Jul 2025 20:44:41 +0100 Subject: [PATCH 25/25] Implement credit card validator function --- .../password-validator.js | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/Sprint-3/4-stretch-investigate/password-validator.js b/Sprint-3/4-stretch-investigate/password-validator.js index b55d527db..7c3bcecb2 100644 --- a/Sprint-3/4-stretch-investigate/password-validator.js +++ b/Sprint-3/4-stretch-investigate/password-validator.js @@ -1,6 +1,48 @@ -function passwordValidator(password) { - return password.length < 5 ? false : true +function isValidCreditCard(cardNumber) { + // Check if cardNumber is exactly 16 characters and all are digits + if (!/^\d{16}$/.test(cardNumber)) { + return false; + } + + // Check if card has at least two different digits + if (/^(\d)\1{15}$/.test(cardNumber)) { + return false; + } + + // Check if last digit is even + const lastDigit = Number(cardNumber[15]); + if (lastDigit % 2 !== 0) { + return false; + } + + // Calculate the sum of all digits and check if greater than 16 + const sum = cardNumber.split('').reduce((acc, digit) => acc + Number(digit), 0); + if (sum <= 16) { + return false; + } + + // All conditions passed, card is valid + return true; } +// Example usage: +// console.log(isValidCreditCard("9999777788880000")); // true +// console.log(isValidCreditCard("4444444444444444")); // false + +module.exports = isValidCreditCard; + +/* + +Explanation: + +The first if uses a regular expression to ensure the card number is exactly 16 digits long and contains only digits. + +The second if uses a regex to check if all digits are the same (e.g., all '4's). + +Then, we check if the last digit is even using modulo %. + +Then, we calculate the sum of all digits with reduce and ensure it is greater than 16. + +Finally, we return true if all these checks pass, else false. -module.exports = passwordValidator; \ No newline at end of file +*/ \ No newline at end of file