Skip to content

Commit 4b85e00

Browse files
committed
implement is done.
1 parent b31a586 commit 4b85e00

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@
1616

1717
function getAngleType(angle) {
1818
// TODO: Implement this function
19+
if (angle <= 0 || angle >= 360) {
20+
return "Invalid angle";
21+
}
22+
23+
if (angle < 90) {
24+
return "Acute angle";
25+
}
26+
27+
if (angle === 90) {
28+
return "Right angle";
29+
}
30+
31+
if (angle < 180) {
32+
return "Obtuse angle";
33+
}
34+
35+
if (angle === 180) {
36+
return "Straight angle";
37+
}
38+
39+
return "Reflex angle";
1940
}
2041

2142
// The line below allows us to load the getAngleType function into tests in other files.
@@ -35,3 +56,12 @@ function assertEquals(actualOutput, targetOutput) {
3556
// Example: Identify Right Angles
3657
const right = getAngleType(90);
3758
assertEquals(right, "Right angle");
59+
assertEquals(getAngleType(45), "Acute angle");
60+
assertEquals(getAngleType(90), "Right angle");
61+
assertEquals(getAngleType(120), "Obtuse angle");
62+
assertEquals(getAngleType(180), "Straight angle");
63+
assertEquals(getAngleType(200), "Reflex angle");
64+
65+
assertEquals(getAngleType(0), "Invalid angle");
66+
assertEquals(getAngleType(-10), "Invalid angle");
67+
assertEquals(getAngleType(360), "Invalid angle");

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
return numerator < denominator;
1516
}
1617

1718
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +32,9 @@ function assertEquals(actualOutput, targetOutput) {
3132

3233
// Example: 1/2 is a proper fraction
3334
assertEquals(isProperFraction(1, 2), true);
35+
assertEquals(isProperFraction(1, 2), true);
36+
assertEquals(isProperFraction(3, 4), true);
37+
assertEquals(isProperFraction(5, 10), true);
38+
assertEquals(isProperFraction(5, 5), false);
39+
assertEquals(isProperFraction(10, 5), false);
40+
assertEquals(isProperFraction(7, 3), false);

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26+
const rank = card.slice(0, card.length - 1);
27+
28+
if (
29+
rank !== "A" &&
30+
rank !== "K" &&
31+
rank !== "Q" &&
32+
rank !== "J" &&
33+
isNaN(rank)
34+
) {
35+
throw new Error("Invalid card");
36+
}
37+
38+
if (rank === "A") {
39+
return 11;
40+
}
41+
42+
if (rank === "K" || rank === "Q" || rank === "J") {
43+
return 10;
44+
}
45+
46+
return Number(rank);
2647
}
2748

2849
// The line below allows us to load the getCardValue function into tests in other files.
@@ -40,6 +61,13 @@ function assertEquals(actualOutput, targetOutput) {
4061
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
4162
// Examples:
4263
assertEquals(getCardValue("9♠"), 9);
64+
assertEquals(getCardValue("A♠"), 11);
65+
assertEquals(getCardValue("K♥"), 10);
66+
assertEquals(getCardValue("Q♦"), 10);
67+
assertEquals(getCardValue("J♣"), 10);
68+
assertEquals(getCardValue("10♠"), 10);
69+
assertEquals(getCardValue("2♥"), 2);
70+
assertEquals(getCardValue("9♣"), 9);
4371

4472
// Handling invalid cards
4573
try {
@@ -52,3 +80,30 @@ try {
5280
}
5381

5482
// What other invalid card cases can you think of?
83+
try {
84+
getCardValue("1♠");
85+
console.error("Should throw error");
86+
} catch (e) {
87+
console.log("Error thrown correctly");
88+
}
89+
90+
try {
91+
getCardValue("11♠");
92+
console.error("Should throw error");
93+
} catch (e) {
94+
console.log("Error thrown correctly");
95+
}
96+
97+
try {
98+
getCardValue("A");
99+
console.error("Should throw error");
100+
} catch (e) {
101+
console.log("Error thrown correctly");
102+
}
103+
104+
try {
105+
getCardValue("♠A");
106+
console.error("Should throw error");
107+
} catch (e) {
108+
console.log("Error thrown correctly");
109+
}

0 commit comments

Comments
 (0)