Skip to content

Commit ba6d069

Browse files
committed
get card value exercise done
1 parent 4b4d8da commit ba6d069

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ assertEquals(equalFraction, false);
7070
const tryZero = isProperFraction(-10, 0);
7171
assertEquals(tryZero, true);
7272

73-
// check if inputs are proper numbers:
73+
// check if inputs are proper numbers
7474
// Input: numerator = "hello", denominator = 4 (any number)
75-
//target output: string
75+
//target output: string "[ wrong input ]"
7676
const tryString = isProperFraction("hello", 4);
7777
assertEquals(tryString, "[ wrong input ]");

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010
function getCardValue(card) {
11+
let rank = card.slice(0, -1);
1112
if (rank === "A") {
1213
return 11;
1314
}
15+
if (rank === "J" || rank === "Q"|| rank === "K") {
16+
return 10;
17+
}
18+
if ((rank => 2) && (rank <= 10)) {
19+
return Number(rank);
20+
}
21+
return "Invalid card rank.";
1422
}
1523

1624
// The line below allows us to load the getCardValue function into tests in other files.
@@ -40,18 +48,25 @@ assertEquals(aceofSpades, 11);
4048
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
4149
const fiveofHearts = getCardValue("5♥");
4250
// ====> write your test here, and then add a line to pass the test in the function above
51+
assertEquals(fiveofHearts, 5);
4352

4453
// Handle Face Cards (J, Q, K):
4554
// Given a card with a rank of "10," "J," "Q," or "K",
4655
// When the function is called with such a card,
4756
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
57+
const faceCards = getCardValue("J♠");
58+
assertEquals(faceCards, 10);
4859

4960
// Handle Ace (A):
5061
// Given a card with a rank of "A",
5162
// When the function is called with an Ace,
5263
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
64+
const ace = getCardValue("A♠");
65+
assertEquals(ace, 11);
5366

5467
// Handle Invalid Cards:
5568
// Given a card with an invalid rank (neither a number nor a recognized face card),
5669
// When the function is called with such a card,
5770
// Then it should throw an error indicating "Invalid card rank."
71+
const invalidCards = getCardValue("hello");
72+
assertEquals(invalidCards, "Invalid card rank.");

0 commit comments

Comments
 (0)