Skip to content

Commit 801d5d8

Browse files
Implement numerical value retrieval for cards 2-9 in getCardValue function and add corresponding test cases
1 parent 876b8a1 commit 801d5d8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
function getCardValue(card) {
1111
var rank = card.slice(0, -1); // get the rank of the card by removing the last character. (the suit is the last character)
1212
if (rank === "A") return 11; // this checks for Aces
13-
if (rank === "5") return 5; // this should check for the number 5
13+
if (rank === "2") return 2; // this checks for the twos
14+
if (rank === "3") return 3; // this checks for the threes
15+
if (rank === "4") return 4; // this checks for the fours
16+
if (rank === "5") return 5; // this should check for fives
17+
if (rank === "6") return 6; // this checks for the sixes
18+
if (rank === "7") return 7; // this checks for the sevens
19+
if (rank === "8") return 8; // this checks for the eights
20+
if (rank === "9") return 9; // this checks for the nines
1421
if (rank === "J") return 10; // this checks for Jacks
1522
if (rank === "Q") return 10; // this checks for Queens
1623
if (rank === "K") return 10; // this checks for Kings
@@ -38,7 +45,13 @@ assertEquals(aceofSpades, 11);
3845
// When the function is called with such a card,
3946
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
4047
const fiveofHearts = getCardValue("5♥");
48+
const sixofDiamonds = getCardValue("6♦");
49+
const sevenofClubs = getCardValue("7♣");
50+
const eightofSpades = getCardValue("8♠");
4151
assertEquals(fiveofHearts, 5);
52+
assertEquals(sixofDiamonds, 6);
53+
assertEquals(sevenofClubs, 7);
54+
assertEquals(eightofSpades, 8);
4255
// ====> write your test here, and then add a line to pass the test in the function above
4356

4457
// Handle Face Cards (J, Q, K):
@@ -59,3 +72,4 @@ assertEquals(kingOfSpades, 10);
5972
// Given a card with an invalid rank (neither a number nor a recognized face card),
6073
// When the function is called with such a card,
6174
// Then it should throw an error indicating "Invalid card rank."
75+

0 commit comments

Comments
 (0)