From 3ab2f5e1cad43bcc802a1cd3403afc42adda3264 Mon Sep 17 00:00:00 2001 From: TaliaK Date: Sat, 25 Jul 2026 11:57:29 +0100 Subject: [PATCH 1/6] implemented function for 1-get-angle-type.js --- .../implement/1-get-angle-type.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 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..d710c424f9 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 @@ -14,8 +14,22 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -function getAngleType(angle) { - // TODO: Implement this function +function getAngleType(angle) + { + 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. From faae9017e4874df237685a960080603bf2dc5307 Mon Sep 17 00:00:00 2001 From: TaliaK Date: Sat, 25 Jul 2026 12:07:28 +0100 Subject: [PATCH 2/6] wrote tests to cover all cases for 1-get-angle-type.js --- .../implement/1-get-angle-type.js | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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 d710c424f9..db50b6192b 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 @@ -46,6 +46,35 @@ function assertEquals(actualOutput, targetOutput) { } // TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles + +// Acute angle +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +// Right angle const right = getAngleType(90); assertEquals(right, "Right angle"); + +// Obtuse angle +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +// Straight angle +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +// Reflex angle +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); + +// Invalid angle (too small) +const invalidLow = getAngleType(0); +assertEquals(invalidLow, "Invalid angle"); + +// Invalid angle (negative) +const invalidNegative = getAngleType(-10); +assertEquals(invalidNegative, "Invalid angle"); + +// Invalid angle (too large) +const invalidHigh = getAngleType(360); +assertEquals(invalidHigh, "Invalid angle"); \ No newline at end of file From fa1a770be9a817992f6b732755872e57836a6e17 Mon Sep 17 00:00:00 2001 From: TaliaK Date: Sat, 25 Jul 2026 12:47:49 +0100 Subject: [PATCH 3/6] implemented function for 2-is-proper-function.js --- .../implement/2-is-proper-fraction.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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..7632cfb6a7 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 @@ -10,8 +10,13 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -function isProperFraction(numerator, denominator) { - // TODO: Implement this function + + function isProperFraction(numerator, denominator) { + if (numerator > 0 && denominator > 0 && numerator < denominator) { + return true; + } else { + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. From 7f79a19acc5c7e627b9a210d9ecb986420c8cb0d Mon Sep 17 00:00:00 2001 From: TaliaK Date: Sat, 25 Jul 2026 12:52:20 +0100 Subject: [PATCH 4/6] wrote tests for 2-is-proper-fraction.js --- .../implement/2-is-proper-fraction.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 7632cfb6a7..a63b57bbb9 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 @@ -36,3 +36,15 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// Numerator > denominator +assertEquals(isProperFraction(4, 1), false); + +// Numerator === denominator +assertEquals(isProperFraction(2, 2), false); + +// Numerator is 0 +assertEquals(isProperFraction(0, 4), false); + +// Denominator is 0 +assertEquals(isProperFraction(6, 0), false); \ No newline at end of file From f84fb7fa43a872199cbc1935ee3f0a050f06348c Mon Sep 17 00:00:00 2001 From: TaliaK Date: Sat, 25 Jul 2026 13:16:56 +0100 Subject: [PATCH 5/6] implemented function for 3-get-card-value.js --- .../implement/3-get-card-value.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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..9168317029 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,8 +22,32 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const rank = card.substring(0, card.length - 1); + const suit = card.slice(-1); + + const validRanks = [ + "A", "2", "3", "4", "5", "6", "7", + "8", "9", "10", "J", "Q", "K" + ]; + + const validSuits = ["♠", "♥", "♦", "♣"]; + + if (!validRanks.includes(rank) || !validSuits.includes(suit)) { + throw new Error("Invalid card"); + } + + if (rank === "A") { + return 11; + } + + if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } + + return Number(rank); } + // TODO: Implement this function + // The line below allows us to load the getCardValue function into tests in other files. // This will be useful in the "rewrite tests with jest" step. From 16736afa8d8bd2acff6394ae158243c45b5b6bb6 Mon Sep 17 00:00:00 2001 From: TaliaK Date: Sat, 25 Jul 2026 13:31:42 +0100 Subject: [PATCH 6/6] wrote tests for 3-get-card-value.js --- .../implement/3-get-card-value.js | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) 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 9168317029..926c884302 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 @@ -63,16 +63,49 @@ 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("Q♠"), 10); +assertEquals(getCardValue("6♠"), 6); // Handling 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("11♠"); + + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("X♠"); + + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("AA"); + + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("9"); + + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} \ No newline at end of file