Skip to content

Commit 7ba78d5

Browse files
added a case for validating the card value in case the rank is invalid.
1 parent c9d4307 commit 7ba78d5

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ function getCardValue(card) {
3232
if (rank === "A") {
3333
return 11;
3434
}
35-
if (+rank >= 2 && +rank <= 9) {
35+
if (rank >= 2 && rank <= 9) {
3636
return +rank;
3737
}
38+
if (!["K", "10", "Q", "J"].includes(rank)){
39+
throw new error (`Invalid card rank: ${rank}`)
40+
}
3841
if (["K", "10", "Q", "J"].includes(rank)) {
3942
return 10;
4043
}
41-
if (!["♠", "♥", "♦", "♣"].includes(cardFace)) {
42-
throw new Error(`Invalid card`);
44+
4345
}
4446

4547

0 commit comments

Comments
 (0)