Skip to content

Commit 057740b

Browse files
committed
Implement getCardValue function with support for number, face, and ace cards; throw error for invalid cards
1 parent 461d0b6 commit 057740b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
function getCardValue(card) {
2-
// replace with your code from key-implement
3-
return 11;
2+
const rank = card.slice(0, -1); // All characters except the last one (suit)
3+
4+
if (!rank) throw new Error("Invalid card rank");
5+
6+
if (rank === "A") return 11;
7+
if (["K", "Q", "J", "10"].includes(rank)) return 10;
8+
9+
const number = Number(rank);
10+
if (number >= 2 && number <= 9) return number;
11+
12+
throw new Error("Invalid card rank");
413
}
5-
module.exports = getCardValue;
14+
15+
module.exports = getCardValue;

0 commit comments

Comments
 (0)