Skip to content

Commit d34d343

Browse files
committed
undefined case
1 parent 4879aaa commit d34d343

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ function getCardValue(card) {
1616
}
1717

1818
const numValue = parseInt(rank, 10);
19-
if (numValue >= 2 && numValue < 10) {
19+
if (numValue >= 2 && numValue <= 10) {
2020
return numValue;
2121
}
22-
if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") {
22+
23+
if (rank === "J" || rank === "Q" || rank === "K") {
2324
return 10;
2425
}
26+
27+
// If we get here, it's an invalid card - return undefined
28+
return undefined;
2529
}
2630

2731
// The line below allows us to load the getCardValue function into tests in other files.
@@ -71,3 +75,6 @@ assertEquals(aceofClubs, 11);
7175
// Given a card with an invalid rank (neither a number nor a recognized face card),
7276
// When the function is called with such a card,
7377
// Then it should throw an error indicating "Invalid card rank."
78+
const invalidCard = getCardValue("1♣");
79+
assertEquals(invalidCard, undefined);
80+

0 commit comments

Comments
 (0)