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
// The line below allows us to load the getCardValue function into tests in other files.
@@ -44,45 +50,28 @@ function assertEquals(actualOutput, targetOutput) {
44
50
);
45
51
}
46
52
47
-
// Acceptance criteria:
48
-
49
-
// 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),
50
-
// When the function getCardValue is called with this card string as input,
51
-
// Then it should return the numerical card value
52
-
constaceofSpades=getCardValue("A♠");
53
-
assertEquals(aceofSpades,11);
53
+
// ---------------- TESTS ----------------
54
54
55
-
// Handle Number Cards (2-10):
56
-
// Given a card with a rank between "2" and "9",
57
-
// When the function is called with such a card,
58
-
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
59
-
constfiveofHearts=getCardValue("5♥");
60
-
assertEquals(fiveofHearts,5);
55
+
// Handle Ace (A)
56
+
constaceOfSpades=getCardValue("A♠");
57
+
assertEquals(aceOfSpades,11);
61
58
62
-
consttenofClubs=getCardValue("10♣");
63
-
assertEquals(tenofClubs,10);
59
+
// Handle Number Cards (2-9)
60
+
constfiveOfHearts=getCardValue("5♥");
61
+
assertEquals(fiveOfHearts,5);
64
62
65
-
// Handle Face Cards (J, Q, K):
66
-
// Given a card with a rank of "J," "Q," or "K",
67
-
// When the function is called with such a card,
68
-
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
69
-
constjackOfDiamonds=getCardValue("J♦");
70
-
assertEquals(jackOfDiamonds,10);
63
+
// Handle 10
64
+
consttenOfClubs=getCardValue("10♣");
65
+
assertEquals(tenOfClubs,10);
71
66
72
-
constqueenOfSpades=getCardValue("Q♠");
73
-
assertEquals(queenOfSpades,10);
67
+
// Handle Face Cards (J, Q, K)
68
+
constqueenOfDiamonds=getCardValue("Q♦");
69
+
assertEquals(queenOfDiamonds,10);
74
70
75
-
constkingOfHearts=getCardValue("K♥");
76
-
assertEquals(kingOfHearts,10);
77
-
78
-
// Handle Invalid Cards:
79
-
// Given a card with an invalid rank (neither a number nor a recognized face card),
80
-
// When the function is called with such a card,
81
-
// Then it should throw an error indicating "Invalid card rank."
71
+
// Handle invalid card
82
72
try{
83
-
getCardValue("Z♠");
73
+
getCardValue("15♣");// invalid rank
74
+
console.assert(false,"Expected error for invalid rank");
84
75
}catch(e){
85
-
assertEquals(e.message,"Invalid card rank.");
76
+
console.assert(true);
86
77
}
87
-
88
-
console.log("All tests ran! If no errors, all passed.");
0 commit comments