Skip to content

Commit 095b908

Browse files
committed
wrote the code for 3-get-card-value and test cases in sprint-3
1 parent cc10398 commit 095b908

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26+
const rank = card.slice(0, -1);
27+
const suit = card.slice(-1);
28+
if (rank === "A") {
29+
return 11;
30+
}
31+
if (rank === "J" || rank === "Q" || rank === "K") {
32+
return 10;
33+
}
34+
return parseInt(rank);
2635
}
2736

2837
// The line below allows us to load the getCardValue function into tests in other files.
@@ -50,3 +59,12 @@ try {
5059
} catch (e) {}
5160

5261
// What other invalid card cases can you think of?
62+
assertEquals(getCardValue("A"), 11); // Missing suit
63+
try {
64+
getCardValue("11♠"); // Invalid rank
65+
console.error("Error was not thrown for invalid rank");
66+
} catch (e) {}
67+
68+
try { getCardValue("9X"); // Invalid suit
69+
console.error("Error was not thrown for invalid suit");
70+
} catch (e) {}

0 commit comments

Comments
 (0)