Skip to content

Commit aceb219

Browse files
committed
1 and 3 updated
1 parent 9faecec commit aceb219

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,19 @@ assertEquals(acute, "Acute angle");
6565
// When the angle is greater than 90 degrees and less than 180 degrees,
6666
// Then the function should return "Obtuse angle"
6767
const obtuse = getAngleType(120);
68+
assertEquals(obtuse, "Obtuse angle");
6869
// ====> write your test here, and then add a line to pass the test in the function above
6970

7071
// Case 4: Identify Straight Angles:
7172
// When the angle is exactly 180 degrees,
7273
// Then the function should return "Straight angle"
74+
const straight = getAngleType(180);
75+
assertEquals(straight, "Straight angle");
7376
// ====> write your test here, and then add a line to pass the test in the function above
7477

7578
// Case 5: Identify Reflex Angles:
7679
// When the angle is greater than 180 degrees and less than 360 degrees,
7780
// Then the function should return "Reflex angle"
81+
const reflex = getAngleType(220);
82+
assertEquals(reflex, "Reflex angle");
7883
// ====> write your test here, and then add a line to pass the test in the function above

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
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+
const rank = card.slice(0, -1);
1112
if (rank === "A") {
1213
return 11;
14+
} else if (["K", "Q", "J", "10"].includes(rank)) {
15+
return 10;
16+
} else if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 9) {
17+
return Number(rank);
18+
} else {
19+
throw new Error("Invalid card rank");
1320
}
1421
}
1522

@@ -31,27 +38,42 @@ function assertEquals(actualOutput, targetOutput) {
3138
// 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),
3239
// When the function getCardValue is called with this card string as input,
3340
// Then it should return the numerical card value
34-
const aceofSpades = getCardValue("A♠");
35-
assertEquals(aceofSpades, 11);
3641

3742
// Handle Number Cards (2-10):
3843
// Given a card with a rank between "2" and "9",
3944
// When the function is called with such a card,
4045
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
41-
const fiveofHearts = getCardValue("5♥");
46+
const fiveOfHearts = getCardValue("5♥");
47+
assertEquals(fiveOfHearts, 5);
4248
// ====> write your test here, and then add a line to pass the test in the function above
4349

4450
// Handle Face Cards (J, Q, K):
4551
// Given a card with a rank of "10," "J," "Q," or "K",
4652
// When the function is called with such a card,
4753
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
54+
const kingOfDiamonds = getCardValue("K♦");
55+
assertEquals(kingOfDiamonds, 10);
56+
57+
const queenOfClubs = getCardValue("Q♣");
58+
assertEquals(queenOfClubs, 10);
59+
60+
const jackOfSpades = getCardValue("J♠");
61+
assertEquals(jackOfSpades, 10);
4862

4963
// Handle Ace (A):
5064
// Given a card with a rank of "A",
5165
// When the function is called with an Ace,
5266
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
67+
const aceOfSpades = getCardValue("A♠");
68+
assertEquals(aceOfSpades, 11);
5369

5470
// Handle Invalid Cards:
5571
// Given a card with an invalid rank (neither a number nor a recognized face card),
5672
// When the function is called with such a card,
5773
// Then it should throw an error indicating "Invalid card rank."
74+
try {
75+
getCardValue("Z♠");
76+
} catch (error) {
77+
console.log("Caught error:", error.message);
78+
assertEquals(error.message, "Invalid card rank");
79+
}

0 commit comments

Comments
 (0)