Skip to content
Open
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Implement a function getAngleType
//
// When given an angle in degrees, it should return a string indicating the type of angle:
// - "Acute angle" for angles greater than 0° and less than 90°
// - "Right angle" for exactly 90°
Expand All @@ -15,12 +14,32 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
if (angle <= 0 || angle >= 360) {
return "Invalid angle";
}

if (angle < 90) {
return "Acute angle";
}
if (angle === 90) {
return "Right angle";
}
if (angle < 180) {
return "Obtuse angle";
}
if (angle === 180) {
return "Straight angle";
}
if (angle < 360) {
return "Reflex angle";
}
}
module.exports = getAngleType;

// TODO: Implement this function

// The line below allows us to load the getAngleType function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getAngleType;

// This helper function is written to make our assertions easier to read.
// If the actual output matches the target output, the test will pass
Expand All @@ -35,3 +54,11 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

// Test
assertEquals(getAngleType(45), "Acute angle");
assertEquals(getAngleType(90), "Right angle");
assertEquals(getAngleType(120), "Obtuse angle");
assertEquals(getAngleType(180), "Straight angle");
assertEquals(getAngleType(270), "Reflex angle");
assertEquals(getAngleType(390), "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,37 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
return numerator < 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.
module.exports = isProperFraction;

// Here's our helper again
// Here's our hel per again
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
module.exports = isProperFraction;

// 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);
//Test
// Proper fraction
assertEquals(isProperFraction(3, 5), true);
assertEquals(isProperFraction(4, 8), true);
assertEquals(isProperFraction(-1, 2), true);
assertEquals(isProperFraction(-1, -2), true);
assertEquals(isProperFraction(1, -2), true);

//Not
assertEquals(isProperFraction(9, 7), false);
assertEquals(isProperFraction(13, 11), false);
assertEquals(isProperFraction(19, 10), false);
assertEquals(isProperFraction(17, 3), false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Your current function cannot yet pass all these tests.

  • You can also test some improper fractions with negative numerator or/and denominator.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have applied the feedbacks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • If you have made any new commit, don't forget to push the commit also to GitHub.

  • If your PR is ready to be re-reviewed, don't forget to add the "Needs Review" label.


//Edge case
assertEquals(isProperFraction(0, 5), true);
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,39 @@
// 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);

const vaildSuits = ["♠", "♥", "♦", "♣"];
const vailRanks = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];

if (!vaildSuits.includes(suit) || !vailRanks.includes(rank)) {
throw new Error("Invalid card");
}
if (rank === "A") return 11;
if (rank === "J" || rank === "Q" || rank === "K") return 10;

return Number(rank);
}

export default getCardValue;

// 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.
module.exports = getCardValue;

// Helper functions to make our assertions easier to read.
function assertEquals(actualOutput, targetOutput) {
Expand All @@ -40,6 +67,10 @@ function assertEquals(actualOutput, targetOutput) {
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);
//Test
assertEquals(getCardValue("A♠"), 11);
assertEquals(getCardValue("J♣"), 10);
assertEquals(getCardValue("10♥"), 10);

// Handling invalid cards
try {
Expand Down
Loading