Skip to content

Commit ac30244

Browse files
committed
exercise 3 is done
1 parent 6937b06 commit ac30244

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Sprint-2/Project-CLI-Treasure-Hunt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 2f622599e09fc28147949f59bcb6892ff6721548

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@
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, card.length-1).toUpperCase();
1112
if (rank === "A") {
1213
return 11;
1314
}
15+
if (rank=="2"||rank=="3"||rank=="4"||rank=="5"||rank=="6"||rank=="7"||rank=="8"||rank=="9"||rank=="10"){
16+
return Number(rank);
17+
};
18+
if (rank==="K"||rank==="Q"||rank==="J"){
19+
return 10;
20+
}
21+
else {
22+
return "Invalid card rank."
23+
}
24+
// for (let i=1; i<10; i++){
25+
// if (i==5){
26+
// return rank === "5"
27+
// }
28+
// }
1429
}
1530

1631
// The line below allows us to load the getCardValue function into tests in other files.
@@ -39,13 +54,21 @@ assertEquals(aceofSpades, 11);
3954
// When the function is called with such a card,
4055
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
4156
const fiveofHearts = getCardValue("5♥");
57+
assertEquals(fiveofHearts, 5);
58+
59+
const sixofSpades = getCardValue("6♠");
60+
assertEquals(sixofSpades, 6);
4261
// ====> write your test here, and then add a line to pass the test in the function above
4362

4463
// Handle Face Cards (J, Q, K):
4564
// Given a card with a rank of "10," "J," "Q," or "K",
4665
// When the function is called with such a card,
4766
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
67+
const kingCard =getCardValue("K♦");
68+
assertEquals(kingCard,10);
4869

70+
const queenCard= getCardValue("Q♣");
71+
assertEquals(queenCard, 10)
4972
// Handle Ace (A):
5073
// Given a card with a rank of "A",
5174
// When the function is called with an Ace,
@@ -55,3 +78,6 @@ const fiveofHearts = getCardValue("5♥");
5578
// Given a card with an invalid rank (neither a number nor a recognized face card),
5679
// When the function is called with such a card,
5780
// Then it should throw an error indicating "Invalid card rank."
81+
82+
const invalidCard= getCardValue("z♣");
83+
assertEquals(invalidCard, "Invalid card rank.")

0 commit comments

Comments
 (0)