Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,11 @@

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 +36,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,8 +23,44 @@

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" ||
!cardRanks.includes(card.slice(0,-1)) ||
!cardSuits.includes(card.slice(-1))
) {
throw new Error("Invalid card");
}

switch (card.slice(0, -1)) {
case "A":
return 11;
case "J":
case "Q":
case "K":
return 10;
default:
return Number(card.slice(0, -1));
}
}



// 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;
Expand All @@ -40,13 +76,28 @@ 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) {}

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