Skip to content

Commit 1bbfbed

Browse files
authored
Refactor getCardValue function for clarity
1 parent 96775b3 commit 1bbfbed

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,27 @@ function getCardValue(card) {
3030
if !(["♠", "♥", "♦", "♣"].includes(suit)) {
3131
throw new Error("Invalid card suit");
3232
}
33-
34-
// Ace value
35-
if (rank === "A") {
36-
return 11;
33+
else
34+
{
35+
// Ace value
36+
if (rank === "A") {
37+
return 11;
38+
}
39+
40+
// Face card values
41+
if (["J", "Q", "K"].includes(rank)) {
42+
return 10;
43+
}
44+
45+
// Number card values ("2" through "10")
46+
const numericValue = parseInt(rank, 10);
47+
if (!isNaN(numericValue) && numericValue >= 2 && numericValue <= 10) {
48+
return numericValue;
49+
}
50+
51+
throw new Error("Invalid card string");
3752
}
3853

39-
// Face card values
40-
if (["J", "Q", "K"].includes(rank)) {
41-
return 10;
42-
}
43-
44-
// Number card values ("2" through "10")
45-
const numericValue = parseInt(rank, 10);
46-
if (!isNaN(numericValue) && numericValue >= 2 && numericValue <= 10) {
47-
return numericValue;
48-
}
49-
50-
throw new Error("Invalid card string");
51-
52-
5354
}
5455

5556
// The line below allows us to load the getCardValue function into tests in other files.

0 commit comments

Comments
 (0)