Skip to content

Commit 366621c

Browse files
Implement logic to handle number and face cards in getCardValue function
1 parent 9f3ed4f commit 366621c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
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-
let rank=card[0]
11+
let rank=card.slice(0,-1)
1212
if (rank=== "A") {
1313
return 11;
1414
}
15-
15+
if(rank>=2 && rank<=9){
16+
return +rank
17+
}
18+
if(rank==="J") {
19+
return 10
20+
}
1621
}
1722

1823
// The line below allows us to load the getCardValue function into tests in other files.
@@ -48,6 +53,8 @@ assertEquals(fiveOfHearts,5)
4853
// Given a card with a rank of "10," "J," "Q," or "K",
4954
// When the function is called with such a card,
5055
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
56+
const faceCards = getCardValue("J♠");
57+
assertEquals(faceCards,10)
5158

5259
// Handle Ace (A):
5360
// Given a card with a rank of "A",

0 commit comments

Comments
 (0)