Skip to content

Commit 922e296

Browse files
committed
solve the invalid issue be using .include() method
1 parent 3e9ab28 commit 922e296

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ function getCardValue(card) {
1515
if (rank === "J" || rank === "Q" || rank === "K") {
1616
return 10;
1717
}
18-
const convertTheStringtoNumber = Number(rank);
19-
if (convertTheStringtoNumber >= 2 && convertTheStringtoNumber <= 10) {
20-
return convertTheStringtoNumber;
21-
} else {
22-
return "Invalid card rank";
23-
}
18+
19+
const validRank = ["2", "3", "4", "5", "6", "7", "8", "9", "10"];
20+
if (validRank.includes(rank)) {
21+
return Number(rank);
22+
} else return "Invalid card rank";
2423
}
2524
// The line below allows us to load the getCardValue function into tests in other files.
2625
// This will be useful in the "rewrite tests with jest" step.

0 commit comments

Comments
 (0)