From 657a9cbb19738ee9b31959738e5921cf3b12f12e Mon Sep 17 00:00:00 2001 From: Rhoda Ajiroba Date: Sat, 25 Jul 2026 05:21:25 +0100 Subject: [PATCH 1/3] Complete Sprint 3 mandatory exercises --- .../implement/1-get-angle-type.js | 45 ++++++++++++++-- .../implement/2-is-proper-fraction.js | 11 +++- .../implement/3-get-card-value.js | 51 ++++++++++++++++--- .../1-get-angle-type.test.js | 25 +++++++++ .../3-get-card-value.test.js | 25 ++++++--- Sprint-3/2-practice-tdd/get-ordinal-number.js | 2 +- Sprint-3/3-dead-code/exercise-1.js | 2 - Sprint-3/3-dead-code/exercise-2.js | 10 ++-- 8 files changed, 141 insertions(+), 30 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..9f9c4ba6fc 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,27 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } + + if (angle === 90) { + return "Right angle"; + } + + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + + if (angle === 180) { + return "Straight angle"; + } + + if (angle > 180 && angle < 360) { + return "Reflex angle"; + } + + return "Invalid angle"; } // The line below allows us to load the getAngleType function into tests in other files. @@ -31,7 +51,22 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); +// Acute angle +assertEquals(getAngleType(45), "Acute angle"); + +// Right angle +assertEquals(getAngleType(90), "Right angle"); + +// Obtuse angle +assertEquals(getAngleType(120), "Obtuse angle"); + +// Straight angle +assertEquals(getAngleType(180), "Straight angle"); + +// Reflex angle +assertEquals(getAngleType(270), "Reflex angle"); + +// Invalid angles +assertEquals(getAngleType(0), "Invalid angle"); +assertEquals(getAngleType(360), "Invalid angle"); +assertEquals(getAngleType(-10), "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..dcd0d782bb 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,7 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + return numerator >= 0 && denominator > 0 && numerator < denominator; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -29,5 +29,12 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases. // What combinations of numerators and denominators should you test? -// Example: 1/2 is a proper fraction +// Proper fractions assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(3, 4), true); + +// Not proper fractions +assertEquals(isProperFraction(2, 2), false); +assertEquals(isProperFraction(5, 2), false); +assertEquals(isProperFraction(-1, 2), false); +assertEquals(isProperFraction(1, 0), false); 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..65320dc32f 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 + const rank = card.slice(0, -1); + const suit = card.slice(-1); + + if (!["♠", "♥", "♦", "♣"].includes(suit)) { + throw new Error("Invalid card"); + } + + if (rank === "A") { + return 11; + } + + if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } + + if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(rank)) { + return Number(rank); + } + + throw new Error("Invalid card"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -37,18 +56,36 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: +// Number cards assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("10♥"), 10); + +// Ace +assertEquals(getCardValue("A♣"), 11); -// Handling invalid cards +// Face cards +assertEquals(getCardValue("J♦"), 10); +assertEquals(getCardValue("Q♥"), 10); +assertEquals(getCardValue("K♠"), 10); + +// Invalid cards try { getCardValue("invalid"); - - // This line will not be reached if an error is thrown as expected console.error("Error was not thrown for invalid card 😢"); } catch (e) { console.log("Error thrown for invalid card 🎉"); } -// What other invalid card cases can you think of? +try { + getCardValue("1♠"); + console.error("Error was not thrown for invalid rank 😢"); +} catch (e) { + console.log("Error thrown for invalid rank 🎉"); +} + +try { + getCardValue("AX"); + console.error("Error was not thrown for invalid suit 😢"); +} catch (e) { + console.log("Error thrown for invalid suit 🎉"); +} diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d3..3c430954ad 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -14,7 +14,32 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test("should return 'Right angle' when angle is 90", () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test("should return 'Obtuse angle' when 90 < angle < 180", () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test("should return 'Straight angle' when angle is 180", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +test("should return 'Reflex angle' when 180 < angle < 360", () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test("should return 'Invalid angle' for invalid values", () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); +}); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index cf7f9dae2e..decc36cecc 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -9,12 +9,23 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards +// Number Cards +test("Should return the value of number cards", () => { + expect(getCardValue("2♥")).toEqual(2); + expect(getCardValue("9♣")).toEqual(9); + expect(getCardValue("10♦")).toEqual(10); +}); -// To learn how to test whether a function throws an error as expected in Jest, -// please refer to the Jest documentation: -// https://jestjs.io/docs/expect#tothrowerror +// Face Cards +test("Should return 10 for face cards", () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♣")).toEqual(10); +}); +// Invalid Cards +test("Should throw an error for invalid cards", () => { + expect(() => getCardValue("1♠")).toThrow(); + expect(() => getCardValue("invalid")).toThrow(); + expect(() => getCardValue("AX")).toThrow(); +}); diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..519f653c47 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,5 @@ function getOrdinalNumber(num) { - return "1st"; + return `${num}st`; } module.exports = getOrdinalNumber; diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa9..5de7eb4ba7 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -5,9 +5,7 @@ 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..78b9e49ddd 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,27 +2,25 @@ // 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)); -} +const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); function countAndCapitalisePets(petsArr) { const petCount = {}; petsArr.forEach((pet) => { const capitalisedPet = pet.toUpperCase(); + if (petCount[capitalisedPet]) { petCount[capitalisedPet] += 1; } else { petCount[capitalisedPet] = 1; } }); + return petCount; } const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); -console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log +console.log(countedPetsStartingWithH); // { HAMSTER: 3, HORSE: 1 } From d8cdf7aac81766cdb87ea4af1a4d205b5f0ab081 Mon Sep 17 00:00:00 2001 From: Rhoda Ajiroba Date: Sat, 25 Jul 2026 05:31:11 +0100 Subject: [PATCH 2/3] Remove get-ordinal-number from Sprint 3 PR --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 519f653c47..f95d71db13 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,5 @@ function getOrdinalNumber(num) { - return `${num}st`; + return "1st"; } module.exports = getOrdinalNumber; From ede74a20a00ace6698976ea10d7ae3fdd8643e23 Mon Sep 17 00:00:00 2001 From: Rhoda Ajiroba Date: Sat, 25 Jul 2026 05:35:52 +0100 Subject: [PATCH 3/3] Remove dead code exercises from Sprint 3 PR --- Sprint-3/3-dead-code/exercise-1.js | 2 ++ Sprint-3/3-dead-code/exercise-2.js | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 5de7eb4ba7..4d09f15fa9 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -5,7 +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 78b9e49ddd..56d7887c4c 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,25 +2,27 @@ // 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 = {}; petsArr.forEach((pet) => { const capitalisedPet = pet.toUpperCase(); - if (petCount[capitalisedPet]) { petCount[capitalisedPet] += 1; } else { petCount[capitalisedPet] = 1; } }); - return petCount; } const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); -console.log(countedPetsStartingWithH); // { HAMSTER: 3, HORSE: 1 } +console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log