Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,30 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
Copy link

Choose a reason for hiding this comment

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

This is good work 👍 You're accounting for most types of angles. But there is a problem here. 0 is also sometimes considered a valid angle. Regardless, if your code assumes that it's valid, it should take that into account, and if it thinks 0 degrees is not a valid angle, it should take that into account as well.
How would you do that?

Copy link
Author

@miriamjorna miriamjorna Mar 17, 2026

Choose a reason for hiding this comment

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

Schrödinger's angle... Initially I thought to return an empty string would be best, but on second thought it's better to just name what we have: "Zero angle"

// TODO: Implement this function
if (angle === 0) {
return "Zero angle";
}
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";
}
if (angle === 360) {
return "This is a circle, not an angle";
}

return "Invalid angle";

}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -35,3 +58,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(-10);
assertEquals(invalid, "Invalid angle");
const invalid2 = getAngleType(361);
assertEquals(invalid2, "Invalid angle");
const circle = getAngleType(360);
assertEquals(circle, "This is a circle, not an angle");

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
// denominator cannot be 0 in a proper fraction
if (denominator === 0) {
Copy link

Choose a reason for hiding this comment

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

Excellent check for 0. Whenever it comes to a division, always check for 0. 🎃

return false;
}

// The numerator must have a smaller absolute value than the denominator
return Math.abs(numerator) < Math.abs(denominator);
}


// 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.
Expand All @@ -31,3 +38,20 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(-1, 2), true);
assertEquals(isProperFraction(1, -2), true);
assertEquals(isProperFraction(-1, -2), true);

// Example: 2/1 is not a proper fraction
assertEquals(isProperFraction(2, 1), false);
assertEquals(isProperFraction(-2, 1), false);
assertEquals(isProperFraction(2, -1), false);
assertEquals(isProperFraction(-2, -1), false);

// Example: 0/5 is a proper fraction
assertEquals(isProperFraction(0, 5), true);
assertEquals(isProperFraction(0, -5), true);

// Example: 5/0 is not a proper fraction
assertEquals(isProperFraction(5, 0), false);
assertEquals(isProperFraction(-5, 0), false);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,32 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function

if (typeof card !== "string") {
Copy link

Choose a reason for hiding this comment

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

So, what you're trying to ensure is that this argument is provided, is a string and can be used down the line. This is a solid approach to do that 👍
However, you also need to ensure it's long enough.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your kind words here and above. Have added a string length criterium.

throw new Error("Card must be a string");
}

if (card.length < 2) {
throw new Error("Card must have at least two characteristics");
}

const rank = card.slice(0, -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 format");
}

if (rank === "A") {
return 11;
} else if (["J", "Q", "K"].includes(rank)) {
return 10;
} else {
return parseInt(rank, 10);
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -39,14 +64,31 @@ function assertEquals(actualOutput, targetOutput) {

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);
assertEquals(getCardValue("9♠"), 9);
assertEquals(getCardValue("A♠"), 11);
assertEquals(getCardValue("J♠"), 10);

// Handling invalid cards
try {
getCardValue("invalid");
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) {}

// What other invalid card cases can you think of?
try {
getCardValue("11♠");
console.error("Error was not thrown for invalid rank");
} catch (e) {}

try {
getCardValue("A♤");
console.error("Error was not thrown for invalid suit");
} catch (e) {}

try {
getCardValue(123);
console.error("Error was not thrown for non-string input");
} catch (e) {}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,40 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when angle is exactly 90`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});
// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
// Test various obtuse angles, including boundary cases
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 exactly 180`, () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
// Test various reflex angles, including boundary cases
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" when angle is outside the valid range`, () => {
// Test various invalid angles
expect(getAngleType(-10)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
});
// Case 7: Circle
test(`should return "This is a circle, not an angle" when angle is exactly 360`, () => {
expect(getAngleType(360)).toEqual("This is a circle, not an angle");
});
// Case 8: Zero angle
test(`should return "Zero angle" when angle is exactly 0`, () => {
expect(getAngleType(0)).toEqual("Zero angle");
});

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,28 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
// Special case: numerator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
expect(isProperFraction(-1, 0)).toEqual(false);
expect(isProperFraction(0, 0)).toEqual(false);
});

test(`should return true when the absolute value of the numerator is less than the absolute value of the denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(1, -2)).toEqual(true);
expect(isProperFraction(-1, -2)).toEqual(true);
});

test(`should return false when the absolute value of the numerator is greater than or equal to the absolute value of the denominator`, () => {
expect(isProperFraction(2, 1)).toEqual(false);
expect(isProperFraction(-2, 1)).toEqual(false);
expect(isProperFraction(2, -1)).toEqual(false);
expect(isProperFraction(-2, -1)).toEqual(false);
expect(isProperFraction(5, 0)).toEqual(false);
expect(isProperFraction(-5, 0)).toEqual(false);
});

test(`should return true when the numerator is zero and the denominator is non-zero`, () => {
expect(isProperFraction(0, 5)).toEqual(true);
expect(isProperFraction(0, -5)).toEqual(true);
});

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,28 @@ test(`Should return 11 when given an ace card`, () => {

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
test(`Should return the correct value for number cards`, () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("10♠")).toEqual(10);
});

// 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);
});

// Invalid Cards
test(`Should throw an error for invalid card strings`, () => {
expect(() => getCardValue("invalid")).toThrow("Invalid card format");
expect(() => getCardValue("11♠")).toThrow("Invalid card format");
expect(() => getCardValue("A♤")).toThrow("Invalid card format");
expect(() => getCardValue(123)).toThrow("Card must be a string");
expect(() => getCardValue(1)).toThrow("Card must have at least two characteristics");
expect(() => getCardValue("")).toThrow("Card must have at least two characteristics");
});

// 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

Loading