Skip to content

Commit 716f047

Browse files
committed
10 card case
1 parent e110722 commit 716f047

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@
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+
// Extract the rank (all characters except the last one which is the suit)
12+
const rank = card.slice(0, -1);
13+
1114
if (rank === "A") {
1215
return 11;
1316
}
17+
18+
const numValue = parseInt(rank, 10);
19+
if (numValue >= 2 && numValue <= 10) {
20+
return numValue;
21+
}
1422
}
1523

1624
// The line below allows us to load the getCardValue function into tests in other files.
@@ -39,6 +47,7 @@ assertEquals(aceofSpades, 11);
3947
// When the function is called with such a card,
4048
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
4149
const fiveofHearts = getCardValue("5♥");
50+
assertEquals(fiveofHearts, 5);
4251
// ====> write your test here, and then add a line to pass the test in the function above
4352

4453
// Handle Face Cards (J, Q, K):

0 commit comments

Comments
 (0)