Skip to content

Commit 93ae4e9

Browse files
committed
Improve error message in getCardValue to include invalid card
1 parent 853d408 commit 93ae4e9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sprint-3/2-mandatory-rewrite/3-get-card-value.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function getCardValue(card) {
22
const rank = card.slice(0, -1); // remove suit
33

4-
if (!rank) throw new Error("Invalid card rank");
4+
if (!rank) throw new Error(`Invalid card rank: ${card}`);
55

66
if (rank === "A") return 11;
77
if (["K", "Q", "J"].includes(rank)) return 10;
88
if (/^(?:[2-9]|10)$/.test(rank)) return Number(rank);
99

10-
throw new Error("Invalid card rank");
10+
throw new Error(`Invalid card rank: ${card}`);
1111
}
1212

1313
module.exports = getCardValue;

0 commit comments

Comments
 (0)