Skip to content

Commit 5c8aac3

Browse files
committed
recognized string values as valid ranks.
1 parent 56ccaef commit 5c8aac3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,30 @@
1010
function getCardValue(card) {
1111
const rank = card.slice(0, -1); // get the rank (before the suit symbol)
1212

13+
14+
const num = Number(rank); // converting to a number.
15+
1316
if (!isNaN(rank)) {
14-
return Number(rank); // Number card
17+
return num; // Number card
1518
}
1619

1720
if (rank === "J" || rank === "Q" || rank === "K") {
1821
return 10; // Face cards
1922
}
2023

21-
if (rank === "A") return 11; // Ace
24+
if (rank === "A") return 11; // Ace
2225

2326
// Anything else is invalid
24-
throw new Error("Invalid card rank");
25-
}
27+
throw new Error("Invalid card rank")
28+
29+
}
30+
31+
console.log(Number("0x002"));
32+
console.log(Number("2.1"));
33+
console.log(Number("9e1"));
34+
console.log(Number("0002"));
35+
36+
2637

2738
// if the rank is not a number or a face card, throw an error(invalid card rank).
2839

0 commit comments

Comments
 (0)