From 9483b2db663510e0d06a3e13aae139f12c04b610 Mon Sep 17 00:00:00 2001 From: shafiekwalker7861 Date: Sun, 21 Jun 2026 18:09:48 +0200 Subject: [PATCH 1/4] Completed Sprint-3/1-implement and rewrite tests/implement --- .../implement/1-get-angle-type.js | 29 ++++++++++++++++++- .../implement/2-is-proper-fraction.js | 10 ++++++- .../implement/3-get-card-value.js | 25 +++++++++++++++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..bdc4b5e432 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -15,7 +15,19 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } else if (angle === 90) { + return "Right angle"; + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { + return "Straight angle"; + } else if (angle > 180 && angle < 360) { + return "Reflex angle"; + } else { + return "Invalid angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -35,3 +47,18 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); + +const invalid = getAngleType(400); +assertEquals(invalid, "Invalid angle"); diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b641..8660763a6c 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -11,7 +11,10 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if ( numerator < denominator && numerator > 0 && denominator > 0) { + return true; + } + return false; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +34,8 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(3, 4), true); +assertEquals(isProperFraction(5, 5), false); +assertEquals(isProperFraction(7, 3), false); +assertEquals(isProperFraction(0, 5), false); +assertEquals(isProperFraction(5, 0), false); \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index ff5c532e1d..a76b9a14b8 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -22,7 +22,26 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + if (card === "A♠" || card === "A♥" || card === "A♦" || card === "A♣") { + return 11; + } + if (card === "J♠" || card === "J♥" || card === "J♦" || card === "J♣") { + return 10; + } + if (card === "Q♠" || card === "Q♥" || card === "Q♦" || card === "Q♣") { + return 10; + } + if (card === "K♠" || card === "K♥" || card === "K♦" || card === "K♣") { + return 10; + } + // Check for number cards + const rank = card.slice(0, -1); + const value = parseInt(rank); + if (!isNaN(value) && value >= 2 && value <= 10) { + return value; + } + // If we reach here, the card is invalid + throw new Error("Invalid card format"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,6 +59,10 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("A♠"), 11); +assertEquals(getCardValue("J♠"), 10); +assertEquals(getCardValue("Q♠"), 10); +assertEquals(getCardValue("K♠"), 10); // Handling invalid cards try { From c34267d8d3cb89d848dcf2b61f3b1d4efe3071ff Mon Sep 17 00:00:00 2001 From: shafiekwalker7861 Date: Sun, 21 Jun 2026 19:22:44 +0200 Subject: [PATCH 2/4] Completed Sprint-3/2-practice-tdd --- Sprint-3/2-practice-tdd/count.js | 2 +- Sprint-3/2-practice-tdd/count.test.js | 7 ++++ Sprint-3/2-practice-tdd/get-ordinal-number.js | 4 ++- Sprint-3/2-practice-tdd/repeat-str.test.js | 33 ++++++++++++++++--- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..26a4575e68 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,5 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + return stringOfCharacters.split(findCharacter).length - 1; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..936120357c 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -17,6 +17,13 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should count zero occurrences of a character", () => { + const str = "aaaaa"; + const char = "b"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..e8e3ea7dd9 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,7 @@ function getOrdinalNumber(num) { - return "1st"; + if (num % 10 === 1 && num % 100 !== 11) { + return num + "st"; + } } module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c4..c240f78229 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -1,5 +1,5 @@ // Implement a function repeatStr -const repeatStr = require("./repeat-str"); + // Given a target string `str` and a positive integer `count`, // When the repeatStr function is called with these inputs, // Then it should: @@ -9,6 +9,16 @@ const repeatStr = require("./repeat-str"); // When the repeatStr function is called with these inputs, // Then it should return a string that contains the original `str` repeated `count` times. +function repeatStr(str, count) { + if (count < 0) { + throw new Error("Count must be a non-negative integer"); + } else if (count === 0) { + return ""; + } else { + return str.repeat(count); + } +} + test("should repeat the string count times", () => { const str = "hello"; const count = 3; @@ -16,17 +26,30 @@ test("should repeat the string count times", () => { expect(repeatedStr).toEqual("hellohellohello"); }); -// Case: handle count of 1: -// Given a target string `str` and a `count` equal to 1, -// When the repeatStr function is called with these inputs, -// Then it should return the original `str` without repetition. +test("should return the original string when count is 1", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hello"); +}); + // Case: Handle count of 0: // Given a target string `str` and a `count` equal to 0, // When the repeatStr function is called with these inputs, // Then it should return an empty string. +test("should return an empty string when count is 0", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual(""); +}); // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. +test("should throw an error for a negative count", () => { + expect(() => repeatStr("hello", -1)).toThrow(); + +}); \ No newline at end of file From df245c802e5cd146ef4267665bb1aae4455fa665 Mon Sep 17 00:00:00 2001 From: shafiekwalker7861 Date: Sun, 21 Jun 2026 19:43:17 +0200 Subject: [PATCH 3/4] completed Sprint-3/3-dead-code --- Sprint-3/3-dead-code/exercise-1.js | 4 ++-- Sprint-3/3-dead-code/exercise-2.js | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa9..6b87e1cc2b 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -5,9 +5,9 @@ let testName = "Jerry"; const greeting = "hello"; function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; + return `${greeting}, ${name}!`; - console.log(greetingStr); + } testName = "Aman"; diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4c..d865830a2e 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,12 +2,10 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); + const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} + function countAndCapitalisePets(petsArr) { const petCount = {}; From 4d308b3175ab096dc5be4ea32e3a619af5dd40e9 Mon Sep 17 00:00:00 2001 From: shafiekwalker7861 Date: Tue, 23 Jun 2026 11:14:04 +0200 Subject: [PATCH 4/4] Completed Sprint-3/4-strecth --- Sprint-3/4-stretch/card-validator.md | 6 ++- Sprint-3/4-stretch/credit-card-validator.js | 39 +++++++++++++++++++ Sprint-3/4-stretch/find.js | 3 ++ Sprint-3/4-stretch/password-validator.js | 20 +++++++++- Sprint-3/4-stretch/password-validator.test.js | 10 ++++- 5 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 Sprint-3/4-stretch/credit-card-validator.js diff --git a/Sprint-3/4-stretch/card-validator.md b/Sprint-3/4-stretch/card-validator.md index e39c6ace6e..7185e2bc17 100644 --- a/Sprint-3/4-stretch/card-validator.md +++ b/Sprint-3/4-stretch/card-validator.md @@ -4,8 +4,8 @@ In this project you'll write a script that validates whether or not a credit car Here are the rules for a valid number: -- Number must be 16 digits, all of them must be numbers. -- You must have at least two different digits represented (all of the digits cannot be the same). +- Number must be 16 digits, all of them must be numbers. checked +- You must have at least two different digits represented (all of the digits cannot be the same). - The final digit must be even. - The sum of all the digits must be greater than 16. @@ -33,3 +33,5 @@ These are the requirements your project needs to fulfill: - Return a boolean from the function to indicate whether the credit card number is valid. Good luck! + +function diff --git a/Sprint-3/4-stretch/credit-card-validator.js b/Sprint-3/4-stretch/credit-card-validator.js new file mode 100644 index 0000000000..cfa3053531 --- /dev/null +++ b/Sprint-3/4-stretch/credit-card-validator.js @@ -0,0 +1,39 @@ +function isValidCreditCard(cardNumber) { + // Rule 1: Must be exactly 16 characters long + if (cardNumber.length !== 16) { + return false; + } + + // Rule 2: Must contain only digits + if (!cardNumber.match(/^\d{16}$/)) { + return false; + } + + // Rule 3: Cannot be made up of only one repeated digit + if (cardNumber.match(/^(.)\1+$/)) { + return false; + } + + // Rule 4: Final digit must be even + const lastDigit = Number(cardNumber[cardNumber.length - 1]); + + if (lastDigit % 2 !== 0) { + return false; + } + + // Rule 5: Sum of all digits must be greater than 16 + let sum = 0; + + for (const digit of cardNumber) { + sum += Number(digit); + } + + if (sum <= 16) { + return false; + } + + // Passed every rule + return true; +} + +module.exports = isValidCreditCard; \ No newline at end of file diff --git a/Sprint-3/4-stretch/find.js b/Sprint-3/4-stretch/find.js index c7e79a2f21..211539bd4c 100644 --- a/Sprint-3/4-stretch/find.js +++ b/Sprint-3/4-stretch/find.js @@ -21,5 +21,8 @@ console.log(find("code your future", "z")); // a) How the index variable updates during the call to find // b) What is the if statement used to check +// the if statement checks characters in the string // c) Why is index++ being used? +// index++ is used to move to the next character in the string for the next iteration of the loop // d) What is the condition index < str.length used for? +// index < str.length keeps the index within the string's valid range. If no match is found by the end, the function returns -1. diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index b55d527dba..eb5054a213 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -1,6 +1,22 @@ function passwordValidator(password) { - return password.length < 5 ? false : true + if (password.length < 5) { + return false; + } else if (!/[A-Z]/.test(password)) { + return false; + } else if (!/[a-z]/.test(password)) { + return false; + } else if (!/[0-9]/.test(password)) { + return false; + } else if (!/[!#$%.*&]/.test(password)) { + return false; + } else { + return true; + } + + } -module.exports = passwordValidator; \ No newline at end of file +module.exports = passwordValidator; + +// ("!", "#", "$", "%", ".", "*", "&") \ No newline at end of file diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 8fa3089d6b..866e6a622b 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -17,10 +17,16 @@ You must breakdown this problem in order to solve it. Find one test case first a const isValidPassword = require("./password-validator"); test("password has at least 5 characters", () => { // Arrange - const password = "12345"; + const password = "2A4a#"; // Act const result = isValidPassword(password); // Assert expect(result).toEqual(true); } -); \ No newline at end of file +); + +test("password must have an uppercase letter", () => { + const password = "2a4a#"; + const result = isValidPassword(password); + expect(result).toEqual(false); +}); \ No newline at end of file