Skip to content
Open
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0c4631a
Implement getAngleType function and add tests
djebsoft Mar 5, 2026
4a2804d
Implement a function getAngleType and Write tests to cover all cases
djebsoft Mar 12, 2026
6b4ee50
implement isproperfraction function and rewrite tests to cover all cases
djebsoft Mar 12, 2026
7d502dc
Implement getCardValue function and added tests for valid and invalid…
djebsoft Mar 13, 2026
82958b5
validate the first if statement to include the condition there the ra…
djebsoft Mar 13, 2026
c286e4a
Revert "validate the first if statement to include the condition ther…
djebsoft Mar 13, 2026
a70220f
add tests for all angle types and invalid angles
djebsoft Mar 13, 2026
bc11ec7
Write tests in Jest syntax to cover all combinations for isProperFrac…
djebsoft Mar 13, 2026
7eab738
Write tests in Jest syntax to cover all possible outcomes.
djebsoft Mar 13, 2026
3f7c3f8
enhancement: Implement getCardValue function to return correct card v…
djebsoft Mar 15, 2026
6769341
fixed syntax error
djebsoft Mar 15, 2026
f231516
combined similar items into one category
djebsoft Mar 16, 2026
608f1db
combined tha ace cases in one category
djebsoft Mar 16, 2026
9a3c314
added tests for negative numerator/denominator cases
djebsoft Mar 16, 2026
c099074
added tests for negative numerator/denominator cases
djebsoft Mar 16, 2026
fa537b2
added tests for negative numerator/denominator cases
djebsoft Mar 16, 2026
36e8c14
converted the cardRnk string to a number and added a check for the ac…
djebsoft Mar 16, 2026
af851f3
combine the tests with the same description into the same group
djebsoft Mar 16, 2026
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
Prev Previous commit
Next Next commit
Implement getCardValue function and added tests for valid and invalid…
… inputs
  • Loading branch information
djebsoft committed Mar 13, 2026
commit 7d502dca76fdbfc2118f7ed763d147757f2ea6ba
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@

function getCardValue(card) {
// TODO: Implement this function
if (
card.length < 2 ||
card.length > 3 ||
!["♠", "♥", "♦", "♣"].includes(card.slice(-1))
)
throw new Error("invalid suit");
if (card[0] === "A") return 11;
if (["J", "Q", "K"].includes(card[0])) return 10;
if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(card[0]))
return card[0]; // the parseint() or Number() can be used to convert the string to a number
throw new Error("invalid rank");
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.

Does your function return the value you expected from each of the following function calls?

getCardValue("+2♠");
getCardValue("2.0♠");
getCardValue("11♠");
getCardValue("2      ♠");
getCardValue("XYZ2♠");

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 tested all these sases and yes it does
the return is either invalid suit or invalid rank
but I made some changes in case as follows:
I declared the suit and rank parts as different variables to get the valid results only when the input maches exactly the condition

}

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

assertEquals(getCardValue("A♥"), 11);
assertEquals(getCardValue("J♣"), 10);
assertEquals(getCardValue("Q♠"), 10);
assertEquals(getCardValue("2♦"), 2);

// Handling invalid cards
try {
getCardValue("invalid");
Expand All @@ -50,3 +66,37 @@ try {
} catch (e) {}

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

try {
getCardValue("AJKP");
console.error("Error was not thrown for invalid card");
} catch (e) {}

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

try {
getCardValue("29");
console.error("Error was not thrown for invalid card");
} catch (e) {}

try {
getCardValue("♦,♣");
console.error("Error was not thrown for invalid card");
} catch (e) {}

try {
getCardValue("2345");
console.error("Error was not thrown for invalid card");
} catch (e) {}

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