Skip to content

Commit 7a3bb54

Browse files
committed
updated getCardValue() function
1 parent 123c3c2 commit 7a3bb54

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ function getCardValue(card) {
1515
if (rank === "J" || rank === "Q"|| rank === "K") {
1616
return 10;
1717
}
18+
19+
rank = Number(Math.floor(rank));
20+
1821
if ((rank => 2) && (rank <= 10)) {
19-
return Number(rank);
22+
return rank;
2023
}
2124
return "Invalid card rank.";
2225
}
@@ -69,4 +72,16 @@ assertEquals(ace, 11);
6972
// When the function is called with such a card,
7073
// Then it should throw an error indicating "Invalid card rank."
7174
const invalidCards = getCardValue("hello");
72-
assertEquals(invalidCards, "Invalid card rank.");
75+
assertEquals(invalidCards, "Invalid card rank.");
76+
77+
// strings that represent valid numeric literals
78+
const numericLiterals1 = getCardValue("hello");
79+
assertEquals(numericLiterals1, "Invalid card rank.");
80+
81+
const numericLiterals2 = getCardValue("hello");
82+
assertEquals(numericLiterals2, "Invalid card rank.");
83+
84+
85+
// console.log(getCardValue("0x02♠")); // 2
86+
// console.log(getCardValue("2.1♠")); // 2
87+
// console.log(getCardValue("0002♠")); // 2

0 commit comments

Comments
 (0)