You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
+29-3Lines changed: 29 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,23 @@
8
8
// write one test at a time, and make it pass, build your solution up methodically
9
9
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
10
10
functiongetCardValue(card){
11
+
constrank=card.slice(0,-1);// <-- answer
12
+
11
13
if(rank==="A"){
12
-
return11;
14
+
return11;// <-- answer
15
+
}
16
+
17
+
if(["K","Q","J","10"].includes(rank)){
18
+
return10;// <-- answer
13
19
}
20
+
21
+
constnum=Number(rank);// <-- answer
22
+
23
+
if(num>=2&&num<=9){
24
+
returnnum;// <-- answer
25
+
}
26
+
27
+
thrownewError("Invalid card rank");// <-- answer
14
28
}
15
29
16
30
// The line below allows us to load the getCardValue function into tests in other files.
@@ -26,32 +40,44 @@ function assertEquals(actualOutput, targetOutput) {
26
40
`Expected ${actualOutput} to equal ${targetOutput}`
27
41
);
28
42
}
43
+
29
44
// Acceptance criteria:
30
45
31
46
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A),
32
47
// When the function getCardValue is called with this card string as input,
33
48
// Then it should return the numerical card value
34
49
constaceofSpades=getCardValue("A♠");
35
-
assertEquals(aceofSpades,11);
50
+
assertEquals(aceofSpades,11);// <-- answer
36
51
37
52
// Handle Number Cards (2-10):
38
53
// Given a card with a rank between "2" and "9",
39
54
// When the function is called with such a card,
40
55
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
41
56
constfiveofHearts=getCardValue("5♥");
42
-
// ====> write your test here, and then add a line to pass the test in the function above
57
+
assertEquals(fiveofHearts,5);// <-- answer
43
58
44
59
// Handle Face Cards (J, Q, K):
45
60
// Given a card with a rank of "10," "J," "Q," or "K",
46
61
// When the function is called with such a card,
47
62
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
0 commit comments