Skip to content

Commit 9483b2d

Browse files
Completed Sprint-3/1-implement and rewrite tests/implement
1 parent b31a586 commit 9483b2d

3 files changed

Lines changed: 61 additions & 3 deletions

File tree

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515
// execute the code to ensure all tests pass.
1616

1717
function getAngleType(angle) {
18-
// TODO: Implement this function
18+
if (angle > 0 && angle < 90) {
19+
return "Acute angle";
20+
} else if (angle === 90) {
21+
return "Right angle";
22+
} else if (angle > 90 && angle < 180) {
23+
return "Obtuse angle";
24+
} else if (angle === 180) {
25+
return "Straight angle";
26+
} else if (angle > 180 && angle < 360) {
27+
return "Reflex angle";
28+
} else {
29+
return "Invalid angle";
30+
}
1931
}
2032

2133
// The line below allows us to load the getAngleType function into tests in other files.
@@ -35,3 +47,18 @@ function assertEquals(actualOutput, targetOutput) {
3547
// Example: Identify Right Angles
3648
const right = getAngleType(90);
3749
assertEquals(right, "Right angle");
50+
51+
const acute = getAngleType(45);
52+
assertEquals(acute, "Acute angle");
53+
54+
const obtuse = getAngleType(120);
55+
assertEquals(obtuse, "Obtuse angle");
56+
57+
const straight = getAngleType(180);
58+
assertEquals(straight, "Straight angle");
59+
60+
const reflex = getAngleType(270);
61+
assertEquals(reflex, "Reflex angle");
62+
63+
const invalid = getAngleType(400);
64+
assertEquals(invalid, "Invalid angle");

‎Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
14+
if ( numerator < denominator && numerator > 0 && denominator > 0) {
15+
return true;
16+
}
17+
return false;
1518
}
1619

1720
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +34,8 @@ function assertEquals(actualOutput, targetOutput) {
3134

3235
// Example: 1/2 is a proper fraction
3336
assertEquals(isProperFraction(1, 2), true);
37+
assertEquals(isProperFraction(3, 4), true);
38+
assertEquals(isProperFraction(5, 5), false);
39+
assertEquals(isProperFraction(7, 3), false);
40+
assertEquals(isProperFraction(0, 5), false);
41+
assertEquals(isProperFraction(5, 0), false);

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,26 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25-
// TODO: Implement this function
25+
if (card === "A♠" || card === "A♥" || card === "A♦" || card === "A♣") {
26+
return 11;
27+
}
28+
if (card === "J♠" || card === "J♥" || card === "J♦" || card === "J♣") {
29+
return 10;
30+
}
31+
if (card === "Q♠" || card === "Q♥" || card === "Q♦" || card === "Q♣") {
32+
return 10;
33+
}
34+
if (card === "K♠" || card === "K♥" || card === "K♦" || card === "K♣") {
35+
return 10;
36+
}
37+
// Check for number cards
38+
const rank = card.slice(0, -1);
39+
const value = parseInt(rank);
40+
if (!isNaN(value) && value >= 2 && value <= 10) {
41+
return value;
42+
}
43+
// If we reach here, the card is invalid
44+
throw new Error("Invalid card format");
2645
}
2746

2847
// The line below allows us to load the getCardValue function into tests in other files.
@@ -40,6 +59,10 @@ function assertEquals(actualOutput, targetOutput) {
4059
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
4160
// Examples:
4261
assertEquals(getCardValue("9♠"), 9);
62+
assertEquals(getCardValue("A♠"), 11);
63+
assertEquals(getCardValue("J♠"), 10);
64+
assertEquals(getCardValue("Q♠"), 10);
65+
assertEquals(getCardValue("K♠"), 10);
4366

4467
// Handling invalid cards
4568
try {

0 commit comments

Comments
 (0)