Skip to content

Commit f84fb7f

Browse files
committed
implemented function for 3-get-card-value.js
1 parent 7f79a19 commit f84fb7f

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,32 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25-
// TODO: Implement this function
25+
const rank = card.substring(0, card.length - 1);
26+
const suit = card.slice(-1);
27+
28+
const validRanks = [
29+
"A", "2", "3", "4", "5", "6", "7",
30+
"8", "9", "10", "J", "Q", "K"
31+
];
32+
33+
const validSuits = ["♠", "♥", "♦", "♣"];
34+
35+
if (!validRanks.includes(rank) || !validSuits.includes(suit)) {
36+
throw new Error("Invalid card");
37+
}
38+
39+
if (rank === "A") {
40+
return 11;
41+
}
42+
43+
if (rank === "J" || rank === "Q" || rank === "K") {
44+
return 10;
45+
}
46+
47+
return Number(rank);
2648
}
49+
// TODO: Implement this function
50+
2751

2852
// The line below allows us to load the getCardValue function into tests in other files.
2953
// This will be useful in the "rewrite tests with jest" step.

0 commit comments

Comments
 (0)