Skip to content
Open
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,30 @@

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

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -35,3 +59,30 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

const acute = getAngleType(1);
assertEquals(acute,"Acute angle");

const obtuse = getAngleType(90.5);
assertEquals(obtuse,"Obtuse angle");

const straight = getAngleType(180);
assertEquals(straight,"Straight angle");

const reflex = getAngleType(359.9);
assertEquals(reflex,"Reflex angle");

const invalid = getAngleType(380);
assertEquals(invalid,"Invalid angle");

const straight2 = getAngleType(180);
assertEquals(straight2,"Straight angle");

const invalid2 = getAngleType(360);
assertEquals(invalid2,"Invalid angle");

const acute2 = getAngleType(0.1);
assertEquals(acute2,"Acute angle");

const invalid3 = getAngleType(0);
assertEquals(invalid3,"Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
numerator = Math.abs(numerator);
denominator = Math.abs(denominator);
if (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 +39,10 @@ function assertEquals(actualOutput, targetOutput) {

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

assertEquals(isProperFraction(1,1),false);
assertEquals(isProperFraction(40234,98543),true);
assertEquals(isProperFraction(2,1),false);
assertEquals(isProperFraction(-10,-1),false);
assertEquals(isProperFraction(-1,-10),true);
assertEquals(isProperFraction(1.5,1),false);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@

function getCardValue(card) {
// TODO: Implement this function
const value = card.slice(0, -1).toUpperCase();
const validSuits = "♠,♥,♦,♣".split(",");
const suit = card.slice(-1);


if(!validSuits.includes(suit)) {
throw new Error("Invalid card");
}

const faceCardValues = {'A': 11, 'J': 10, 'Q': 10, 'K': 10};

if (faceCardValues[value] !== undefined) {
return faceCardValues[value];
}

const numvalue = Number(value);
if (numvalue >= 2 && numvalue <= 10) {
return numvalue;
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -41,6 +60,14 @@ function assertEquals(actualOutput, targetOutput) {
// Examples:
assertEquals(getCardValue("9♠"), 9);

assertEquals(getCardValue("A♥"),11);
assertEquals(getCardValue("10♠"),10);


assertEquals(getCardValue("2♠"), 2);
assertEquals(getCardValue("K♠"), 10);
assertEquals(getCardValue("q♦"), 10);
assertEquals(getCardValue("J♣"), 10);
// Handling invalid cards
try {
getCardValue("invalid");
Expand Down
Loading