From 9483b2db663510e0d06a3e13aae139f12c04b610 Mon Sep 17 00:00:00 2001 From: shafiekwalker7861 Date: Sun, 21 Jun 2026 18:09:48 +0200 Subject: [PATCH 1/3] 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 6f25207d8acbe3d267d5e1b99092d518c4b7f432 Mon Sep 17 00:00:00 2001 From: shafiekwalker7861 Date: Mon, 29 Jun 2026 19:14:44 +0200 Subject: [PATCH 2/3] Simplify isProperFraction logic and add tests for negative values --- .../implement/2-is-proper-fraction.js | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 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 8660763a6c..41594af683 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,32 +10,36 @@ // 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) { - 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. // This will be useful in the "rewrite tests with jest" step. module.exports = isProperFraction; // Here's our helper again +function isProperFraction(numerator, denominator) { + return ( + denominator !== 0 && + numerator !== 0 && + Math.abs(numerator) < Math.abs(denominator) + ); +} + +// TODO: Write tests to cover all cases. +// What combinations of numerators and denominators should you test? function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, `Expected ${actualOutput} to equal ${targetOutput}` ); } - -// TODO: Write tests to cover all cases. -// What combinations of numerators and denominators should you test? - // 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 +assertEquals(isProperFraction(5, 0), false); +assertEquals(isProperFraction(1, -2), true); +assertEquals(isProperFraction(-1, -2), true); +assertEquals(isProperFraction(-7, 3), false); \ No newline at end of file From 6681cfab2ccfb18884cdaa9521f9f280285e8a2e Mon Sep 17 00:00:00 2001 From: shafiekwalker7861 Date: Tue, 30 Jun 2026 13:34:56 +0200 Subject: [PATCH 3/3] Simplify getCardValue implementation --- .../implement/3-get-card-value.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 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 a76b9a14b8..9f75661f6f 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,20 +22,17 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - if (card === "A♠" || card === "A♥" || card === "A♦" || card === "A♣") { + + // Check for number cards + const rank = card.slice(0, -1); + + if (rank === "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♣") { + + if (["J", "Q", "K"].includes(rank)) { 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;