Skip to content

Commit 48e6a8c

Browse files
committed
added the console.assert test
1 parent 121696e commit 48e6a8c

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

Sprint-3/implement/get-card-value.js

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,48 @@
3636

3737
// ========================= getCardValue ===========================
3838

39-
function getCardValue (input){
39+
function getCardValue(input) {
4040
const rank = input.slice(0, -1);
41+
const suit = input.slice(-1);
4142

42-
// console.log(rank)
43-
// return rank//fist character
4443

45-
if (input === "10")
44+
if (input === "10"){
4645
return 10;
47-
48-
else if (rank > 1 && rank < 11) {
46+
}else if (rank > 1 && rank < 11) {
4947
return Number(rank);
50-
}
51-
else if(input === "A")
52-
return 11
53-
54-
else if (
55-
input.toUpperCase() === "K" ||
56-
input.toUpperCase() === "Q" ||
57-
input.toUpperCase() === "J"
58-
) {
48+
}
49+
else if (input === "A")
50+
return 11;
51+
else if (input.toUpperCase() === "K" || input.toUpperCase() === "Q" || input.toUpperCase() === "J"){
5952
return 10;
6053
}
61-
else return "Invalid card rank.";
6254

55+
if (suit !== "♠" && suit !== "♥" && suit !== "♣" && suit !== "♦" && input.length > 1) {
56+
return "Invalid card rank.";
57+
}
6358
}
6459

6560

66-
// // Test cases
67-
console.log(getCardValue("10")); // Output: 10
68-
console.log(getCardValue("10♠")); // Output: 10
69-
console.log(getCardValue("5♥")); // Output: 5
70-
console.log(getCardValue("A")); // Output: 11
71-
console.log(getCardValue("k$")); // output Invalid card rank.
72-
console.log(getCardValue("k")); // output 10
61+
// ======================== Test cases console.log() =====================
62+
63+
// console.log(getCardValue("10")); // Output: 10
64+
// console.log(getCardValue("10♠")); // Output: 10
65+
// console.log(getCardValue("5♥")); // Output: 5
66+
// console.log(getCardValue("A")); // Output: 11
67+
// console.log(getCardValue("k$")); // output Invalid card rank.
68+
// console.log(getCardValue("k")); // output 10
7369

7470

71+
// ======================== Test console.assert =====================
72+
73+
console.assert(getCardValue("10") === 10, "Test case failed for input '10'");
74+
console.assert(getCardValue("10♠") === 10, "Test case failed for input '10♠'");
75+
console.assert(getCardValue("5♥") === 5, "Test case failed for input '5♥'");
76+
console.assert(getCardValue("A") === 11, "Test case failed for input 'A'");
77+
console.assert(getCardValue("K") === 10, "Test case failed for input 'K'");
78+
console.assert(getCardValue("3X") === "Invalid card rank.", "Test case failed for input '3X'");
79+
80+
console.log("All tests passed!");
7581

7682

7783
// ========================== optimized version =======================
@@ -112,5 +118,3 @@ console.log(getCardValue("k")); // output 10
112118
// console.log(getCardValue("K$")); // Output: "Invalid card suit."
113119
// console.log(getCardValue("K")); // Output: 10
114120
// console.log(getCardValue("11♥")); // Output: "Invalid card rank."
115-
116-

0 commit comments

Comments
 (0)