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/implement/get-card-value.js
+37-3Lines changed: 37 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -6,19 +6,23 @@
6
6
7
7
// Acceptance criteria:
8
8
9
-
// 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),
9
+
// Given a card string in the format "A♠" (representing a card in blackjack -
10
+
// the last character will always be an emoji for a suit, and all characters
11
+
// before will be a number 2-10, or one letter of J, Q, K, A),
10
12
// When the function getCardValue is called with this card string as input,
11
13
// Then it should return the numerical card value
12
14
13
15
// Handle Number Cards (2-10):
14
16
// Given a card with a rank between "2" and "9",
15
17
// When the function is called with such a card,
16
-
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
18
+
// Then it should return the numeric value corresponding to the rank
19
+
// (e.g., "5" should return 5).
17
20
18
21
// Handle Face Cards (J, Q, K):
19
22
// Given a card with a rank of "10," "J," "Q," or "K",
20
23
// When the function is called with such a card,
21
-
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
24
+
// Then it should return the value 10, as these cards are worth 10 points each
25
+
// in blackjack.
22
26
23
27
// Handle Ace (A):
24
28
// Given a card with a rank of "A",
@@ -29,3 +33,33 @@
29
33
// Given a card with an invalid rank (neither a number nor a recognized face card),
30
34
// When the function is called with such a card,
31
35
// Then it should throw an error indicating "Invalid card rank."
36
+
37
+
38
+
functionIdentifyNumberCard(input){
39
+
//we validate and convert into str and upperCase before to compare with our local var
40
+
constchain=input.toString().toUpperCase();
41
+
42
+
//Option that we want to check
43
+
constfaceCards=["K","J","Q","10"];
44
+
constace="A";
45
+
constnumberCards=[1,2,3,4,5,6,7,8,9];
46
+
constsuits=["♠","♥","♣","♦"];
47
+
48
+
if(faceCards.includes(chain)){
49
+
return10;
50
+
}
51
+
//!isNaN(chain) ensures that chain is a valid number or a string representation of a number.
52
+
//to validate the string and verify is a number or string ("abc")=> false, ("1")=>true
53
+
//!isNaN is not a number? true is number. && convert the chain into number and compare if the input is the NumberCard
0 commit comments