Skip to content
Open
Copy link

@A-O-Emmanuel A-O-Emmanuel Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your implementation of the getAngleType function is logically correct, and follow TDD principles good work

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ function getAngleType(angle) {
return "Right angle";
}
// Run the tests, work out what Case 2 is testing, and implement the required code here.
if (angle < 90) {
return "Acute angle";
}
// Then keep going for the other cases, one at a time.
if (angle > 90 && angle < 180) {
return "Obtuse angle";
}
if (angle === 180) {
return "Straight angle";
}
if (angle > 180 && angle < 360) {
return "Reflex angle";
}

}

// The line below allows us to load the getAngleType function into tests in other files.
Expand Down Expand Up @@ -50,14 +63,19 @@ assertEquals(acute, "Acute angle");
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
assertEquals(obtuse, "Obtuse angle");
// ====> write your test here, and then add a line to pass the test in the function above

// 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
// ====> write your test here, and then add a line to pass the test in the function above
const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to work on the other two acceptance criterias not accounted for. The instruction says: "complete the rest of the tests and cases", you have completed two cases in the acceptance criteria and two cases in the strech, you need to complete the remaining two cases in the acceptance criteria.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amended to address the remaining 2 cases in acceptance criteria

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) {
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches acceptance criteria 1 which is "proper fraction check"

}
if (numerator >= denominator) {
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches acceptance criteria 2 which is "improper fraction check"

if(numerator == 0){
return true;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a stretch scenario I created, I have updated the code to ensure the condition also checks that the denominator is non-zero.
Please let me know if this is sufficient.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches stretch scenario 1 which "Zero numerator check"

if (denominator === 0) {
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches stretch scenario 2 which is "zero denominator check"

}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand Down Expand Up @@ -47,13 +56,48 @@ assertEquals(improperFraction, false);
// 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?
// Zero Numerator check:
// Input: numerator = 0, denominator = 5
// target output: true
// Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). The function should return true.
const zeroNumerator = isProperFraction(0, 5);
// ====> complete with your assertion
assertEquals(zeroNumerator, true);
// Zero Denominator check:
// Input: numerator = 4, denominator = 0
// target output: false
// Explanation: The fraction 4/0 is undefined because division by zero is not allowed. The function should return false.
const zeroDenominator = isProperFraction(4, 0);
// ====> complete with your assertion
assertEquals(zeroDenominator, false);
// Negative Denominator check:
// Input: numerator = 3, denominator = -5
// target output: true
// Explanation: The fraction 3/-5 is a proper fraction because the absolute value of the numerator (3) is less than the absolute value of the denominator (5). The function should return true.
const negativeDenominator = isProperFraction(3, -5);
// ====> complete with your assertion
assertEquals(negativeDenominator, true);
// Both Negative check:
// Input: numerator = -2, denominator = -6
// target output: true
// Explanation: The fraction -2/-6 is a proper fraction because the absolute value of the numerator (2) is less than the absolute value of the denominator (6). The function should return true.
const bothNegative = isProperFraction(-2, -6);
// ====> complete with your assertion
assertEquals(bothNegative, true);
// Zero Numerator and Denominator check:
// Input: numerator = 0, denominator = 0
// target output: false
// Explanation: The fraction 0/0 is undefined. The function should return false.
const zeroNumeratorDenominator = isProperFraction(0, 0);
// ====> complete with your assertion
assertEquals(zeroNumeratorDenominator, false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should review the acceptance criteria again for this and follow it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amended to throw error as opposed to returning for invalid cards

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,32 @@
// 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)
const suit = card.slice(-1)
if (!["♠","♥","♦","♣"].includes(suit)) {
return "Invalid card rank.";
}
switch(rank) {
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
return parseInt(rank);
case "10":
case "J":
case "Q":
case "K":
return 10;
case "A":
return 11;
default:
return "Invalid card rank.";
}

}

// The line below allows us to load the getCardValue function into tests in other files.
Expand Down Expand Up @@ -40,18 +63,36 @@ assertEquals(aceofSpades, 11);
// 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 kingofDiamonds = getCardValue("K♦");
assertEquals(kingofDiamonds, 10);

const tenofClubs = getCardValue("10♣");
assertEquals(tenofClubs, 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 aceofHearts = getCardValue("A♥");
assertEquals(aceofHearts, 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."

const invalidCard = getCardValue("1♠");
assertEquals(invalidCard, "Invalid card rank.");

const invalidCard2 = getCardValue("B♦");
assertEquals(invalidCard2, "Invalid card rank.");

const invalidCard3 = getCardValue("11");
assertEquals(invalidCard3, "Invalid card rank.");

const invalidCard4 = getCardValue("3😄");
assertEquals(invalidCard4, "Invalid card rank.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test are okay

Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ test("should identify right angle (90°)", () => {
// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
test("should identify acute angle (<90°)", () => {
expect(getAngleType(45)).toEqual("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"

test("should identify obtuse angle (>90° and <180°)", () => {
expect(getAngleType(120)).toEqual("Obtuse angle");
});
// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"

test("should identify straight angle (180°)", () => {
expect(getAngleType(180)).toEqual("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"
test("should identify reflex angle (>180° and <360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test structure is okay

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,30 @@ 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);
});

// Case 5: Zero Numerator:
test("should return true for zero numerator", () => {
expect(isProperFraction(0, 5)).toEqual(true);
});

// Case 6: Zero Denominator:
test("should return false for zero denominator", () => {
expect(isProperFraction(4, 0)).toEqual(false);
});

// Case 7: Negative Denominator:
test("should return true for negative denominator", () => {
expect(isProperFraction(3, -5)).toEqual(true);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test structure here looks okay, just confirm that the get-card-value.js follows the acceptance criteria

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amended to throw error as opposed to returning error for invalid cards

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ test("should return 11 for Ace of Spades", () => {
});

// Case 2: Handle Number Cards (2-10):
test("should return correct value for number cards", () => {
expect(getCardValue("2♣")).toEqual(2);
expect(getCardValue("5♦")).toEqual(5);
expect(getCardValue("10♥")).toEqual(10);
})
// Case 3: Handle Face Cards (J, Q, K):
test("should return 10 for face cards", () => {
expect(getCardValue("J♣")).toEqual(10);
expect(getCardValue("Q♦")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
})
// Case 4: Handle Ace (A):
test("should return 11 for Ace cards", () => {
expect(getCardValue("A♣")).toEqual(11);
expect(getCardValue("A♦")).toEqual(11);
expect(getCardValue("A♥")).toEqual(11);
})
// Case 5: Handle Invalid Cards:
test("should return Invalid card rank for invalid cards", () => {
expect(getCardValue("1♣")).toEqual("Invalid card rank.");
expect(getCardValue("11♦")).toEqual("Invalid card rank.");
expect(getCardValue("3")).toEqual("Invalid card rank.");
expect(getCardValue("3😄")).toEqual("Invalid card rank.");
})
Loading
Loading