Skip to content

Commit a52f2c1

Browse files
committed
Update: implement getCardValue function to return correct card values and add test cases
1 parent 87fc686 commit a52f2c1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
function getCardValue(card) {
2-
// replace with your code from key-implement
3-
return 11;
2+
// replace with your code from key-implement
3+
// return 11; // always return 11 for testing purposes that is wrong
4+
const rank = card.slice(0, -1); // Extract rank (everything except the last character)
5+
if (rank === "A") return 11; // handle Ace as 11
6+
if (["K", "Q", "J"].includes(rank)) return 10; // handle face cards as 10
7+
const numerincRank = parseInt(rank); //Handle number cards 2–9
8+
if (numerincRank >= 2 && numerincRank <= 9) {
9+
return numerincRank; // Return the numeric value for cards 2-9
10+
}
11+
// Invalid card rank
12+
return 0;
413
}
5-
module.exports = getCardValue;
14+
module.exports = getCardValue;
15+
16+
// // Test cases
17+
console.log(getCardValue("A♠")); // 11
18+
console.log(getCardValue("7♥")); // 7
19+
console.log(getCardValue("K♦")); // 10
20+
console.log(getCardValue("A♣")); // 11

0 commit comments

Comments
 (0)