Skip to content

Commit c94ac7b

Browse files
committed
fixed error
1 parent 95a7938 commit c94ac7b

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,25 @@ function getCardValue(card) {
2525
const rank = card.slice(0, -1);
2626
const suit = card.slice(-1);
2727

28-
const vaildSuits = ["♠", "♥", "♦", "♣"];
29-
const vailRanks = ["A","2","3","4","5","6","7","8","9","10","J","Q","k"];
30-
31-
if (!vaildSuits.includes(suit) || !validRanks.inculdes(rank)){
32-
throw new Error("Invaild card");
28+
const vaildSuits = ["♠", "♥", "♦", "♣"];
29+
const vailRanks = [
30+
"A",
31+
"2",
32+
"3",
33+
"4",
34+
"5",
35+
"6",
36+
"7",
37+
"8",
38+
"9",
39+
"10",
40+
"J",
41+
"Q",
42+
"K",
43+
];
44+
45+
if (!vaildSuits.includes(suit) || !vailRanks.includes(rank)) {
46+
throw new Error("Invalid card");
3347
}
3448
if (rank === "A") return 11;
3549
if (rank === "J" || rank === "Q" || rank === "K") return 10;
@@ -39,11 +53,9 @@ const vaildSuits = ["♠", "♥", "♦", "♣"];
3953

4054
module.exports = getCardValue;
4155

42-
4356
// The line below allows us to load the getCardValue function into tests in other files.
4457
// This will be useful in the "rewrite tests with jest" step.
4558

46-
4759
// Helper functions to make our assertions easier to read.
4860
function assertEquals(actualOutput, targetOutput) {
4961
console.assert(
@@ -56,17 +68,16 @@ function assertEquals(actualOutput, targetOutput) {
5668
// Examples:
5769
assertEquals(getCardValue("9♠"), 9);
5870
//Test
59-
assertEquals(getCardvalue("A♠"), 11);
60-
assertEquals(getCardEqual("J♣), 10);
61-
assertEquals(getCardequal("10♥"), 10);
71+
assertEquals(getCardValue("A♠"), 11);
72+
assertEquals(getCardValue("J♣"), 10);
73+
assertEquals(getCardValue("10♥"), 10);
6274

6375
// Handling invalid cards
6476
try {
6577
getCardValue("invalid");
66-
6778

6879
// This line will not be reached if an error is thrown as expected
6980
console.error("Error was not thrown for invalid card");
7081
} catch (e) {}
7182

72-
// What other invalid card cases can you think of?
83+
// What other invalid card cases can you think of?

0 commit comments

Comments
 (0)