Skip to content

Commit ce08a1f

Browse files
authored
3-get-card-value.js
1 parent d276533 commit ce08a1f

File tree

1 file changed

+1
-40
lines changed

1 file changed

+1
-40
lines changed

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

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,9 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010
function getCardValue(card) {
11-
const rank = card.slice(0, -1);
1211
if (rank === "A") {
1312
return 11;
1413
}
15-
if (["10", "J", "Q", "K"].includes(rank)) {
16-
return 10;
17-
}
18-
if (["2", "3", "4", "5", "6", "7", "8", "9"].includes(rank)) {
19-
return parseInt(rank, 10);
20-
}
21-
return "Invalid card rank";
2214
}
2315

2416
// The line below allows us to load the getCardValue function into tests in other files.
@@ -46,51 +38,20 @@ assertEquals(aceofSpades, 11);
4638
// Given a card with a rank between "2" and "9",
4739
// When the function is called with such a card,
4840
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
49-
const fiveofHearts = getCardValue("5♥");
41+
const fiveofHearts = getCardValue("5♥");
5042
// ====> write your test here, and then add a line to pass the test in the function above
51-
assertEquals(fiveofHearts, 5);
5243

5344
// Handle Face Cards (J, Q, K):
5445
// Given a card with a rank of "10," "J," "Q," or "K",
5546
// When the function is called with such a card,
5647
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
57-
const kingofDiamonds = getCardValue("K♦");
58-
assertEquals(kingofDiamonds, 10);
59-
60-
const jackofHearts = getCardValue("J♥");
61-
assertEquals(jackofHearts, 10);
62-
63-
const queenofSpades = getCardValue("Q♠");
64-
assertEquals(queenofSpades, 10);
65-
66-
const tenofClubs = getCardValue("10♣");
67-
assertEquals(tenofClubs, 10);
6848

6949
// Handle Ace (A):
7050
// Given a card with a rank of "A",
7151
// When the function is called with an Ace,
7252
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
73-
const aceofClubs = getCardValue("A♣");
74-
assertEquals(aceofClubs, 11);
7553

7654
// Handle Invalid Cards:
7755
// Given a card with an invalid rank (neither a number nor a recognized face card),
7856
// When the function is called with such a card,
7957
// Then it should throw an error indicating "Invalid card rank."
80-
const invalidCard = getCardValue("1♠");
81-
assertEquals(invalidCard, "Invalid card rank");
82-
const invalidCard2 = getCardValue("11♠");
83-
assertEquals(invalidCard2, "Invalid card rank");
84-
const invalidCard3 = getCardValue("B♠");
85-
assertEquals(invalidCard3, "Invalid card rank");
86-
87-
88-
console.log( getCardValue("1♠"));
89-
console.log( getCardValue("11♠"));
90-
console.log( getCardValue("B♠"));
91-
console.log( getCardValue("3♠"));
92-
console.log( getCardValue("10♠"));
93-
console.log( getCardValue("J♠"));
94-
console.log( getCardValue("Q♠"));
95-
console.log( getCardValue("K♠"));
96-
console.log( getCardValue("A♠"));

0 commit comments

Comments
 (0)