Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@

function getAngleType(angle) {
// TODO: Implement this function
switch (true) {
case (0 < angle && angle < 90):
return "Acute angle";
case (angle === 90):
return "Right angle";
case (90 < angle && angle < 180):
return "Obtuse angle";
case (angle === 180):
return "Straight angle";
case (180 < angle && angle < 360):
return "Reflex angle";
case ( angle <= 0 || angle >= 360) :
return "Invalid angle";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -33,5 +47,30 @@ 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 (below range)
const invalidLow = getAngleType(0);
assertEquals(invalidLow, "Invalid angle");

// Invalid angle (above range)
const invalidHigh = getAngleType(360);
assertEquals(invalidHigh, "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

function isProperFraction(numerator, denominator) {
// TODO: Implement this function

if (
numerator >= 0 &&
denominator >= 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.
Expand All @@ -31,3 +42,9 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction("2", 2), false);
assertEquals(isProperFraction(3, 4), true);
assertEquals(isProperFraction(5, 10), true);
assertEquals(isProperFraction(-4, 2), false);
assertEquals(isProperFraction(-4, 10), false);
assertEquals(isProperFraction(123123213n, 0), false);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,45 @@

function getCardValue(card) {
// TODO: Implement this function
const cardRanks = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];
const cardSuits = ["♠", "♥", "♦", "♣"];
if (typeof card !== "string") {
throw new Error("Invalid card");
}

let rank = card.slice(0, -1);
let suit = card.slice(-1);
if (
!cardRanks.includes(rank) ||
!cardSuits.includes(suit)
) {
throw new Error("Invalid card");
}

switch (rank) {
case "A":
return 11;
case "J":
case "Q":
case "K":
return 10;
default:
return Number(rank);
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -40,15 +79,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("A♥"), 11);
assertEquals(getCardValue("J♥"), 10);
assertEquals(getCardValue("Q♦"), 10);
assertEquals(getCardValue("K♣"), 10);
assertEquals(getCardValue("10♠"), 10);
assertEquals(getCardValue("5♠"), 5);


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

try {
getCardValue("A");
console.error("Expected error for 'A' but none was thrown");
} catch (e) {}

try {
getCardValue("♠");
console.error("Expected error for '♠' but none was thrown");
} catch (e) {}

// What other invalid card cases can you think of?
Loading
Loading