Skip to content

Commit 5dd3b88

Browse files
committed
Rewrote the Card value function and tests
1 parent 68f5551 commit 5dd3b88

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

Sprint-3/1-key-implement/3-get-card-value.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ function getCardValue(card) {
1818
return 10; // Face cards
1919
}
2020

21-
if (rank === "A") {
22-
return 11; // Ace
23-
}
21+
if (rank === "A") return 11; // Ace
2422

2523
// Anything else is invalid
2624
throw new Error("Invalid card rank");
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
function getCardValue(card) {
2-
// replace with your code from key-implement
3-
return 11;
2+
if (rank === "A") return 11;
43
}
5-
module.exports = getCardValue;
4+
module.exports = getCardValue;

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
const getCardValue = require("./3-get-card-value");
22

33
test("should return 11 for Ace of Spades", () => {
4-
const aceofSpades = getCardValue("A♠");
5-
expect(aceofSpades).toEqual(11);
6-
});
4+
const aceofSpades = getCardValue("A♠");
5+
expect(aceofSpades).toEqual(11);
6+
});
7+
8+
const aceofSpades = getCardValue("A♠");
9+
assertEquals(aceofSpades, 11);
10+
11+
const fiveofHearts = getCardValue("5♥");
12+
assertEquals(fiveofHearts, 5);
13+
14+
const tenofDiamonds = getCardValue("10♦");
15+
assertEquals(tenofDiamonds, 10);
16+
17+
const jackofClubs = getCardValue("J♣");
18+
assertEquals(jackofClubs, 10);
19+
20+
const queenofHearts = getCardValue("Q♥");
21+
assertEquals(queenofHearts, 10);
22+
23+
const kingofSpades = getCardValue("K♠");
24+
assertEquals(kingofSpades, 10);
25+
26+
try {
27+
getCardValue("Z♠");
28+
} catch (error) {
29+
console.log("Caught error:", error.message);
30+
}
731

832
// Case 2: Handle Number Cards (2-10):
933
// Case 3: Handle Face Cards (J, Q, K):

0 commit comments

Comments
 (0)