Skip to content

Commit 12ae68f

Browse files
committed
complete the function to get the angle type
1 parent 113d089 commit 12ae68f

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,35 @@
66
// The assertion error will tell you what the expected output is
77
// Write the code to pass the test
88
// Then, write the next test! :) Go through this process until all the cases are implemented
9-
9+
// Run the tests, work out what Case 2 is testing, and implement the required code here.
10+
// Case 1: Right angle
1011
function getAngleType(angle) {
1112
if (angle === 90) {
1213
return "Right angle";
14+
}
15+
// Case 2: Acute angle
16+
else if (angle < 90) {
17+
return "Acute angle";
1318
}
14-
// Run the tests, work out what Case 2 is testing, and implement the required code here.
15-
// Then keep going for the other cases, one at a time.
16-
}
17-
19+
// Case 3: Obtuse angle
20+
else if (angle > 90 && angle < 180) {
21+
return "Obtuse angle";
22+
}
23+
// Case 4: Straight angle
24+
else if (angle === 180) {
25+
return "Straight angle";
26+
}
27+
// Case 5: Reflex angle
28+
else if (angle > 180 && angle < 360) {
29+
return "Reflex angle";
30+
}
31+
else {
32+
return "Invalid angle"; // Optional: handles 0 or ≥ 360
33+
}
34+
1835
// The line below allows us to load the getAngleType function into tests in other files.
1936
// This will be useful in the "rewrite tests with jest" step.
2037
module.exports = getAngleType;
21-
2238
// we're going to use this helper function to make our assertions easier to read
2339
// if the actual output matches the target output, the test will pass
2440
function assertEquals(actualOutput, targetOutput) {
@@ -50,14 +66,21 @@ assertEquals(acute, "Acute angle");
5066
// When the angle is greater than 90 degrees and less than 180 degrees,
5167
// Then the function should return "Obtuse angle"
5268
const obtuse = getAngleType(120);
69+
assertEquals(obtuse, "Obtuse angle");
5370
// ====> write your test here, and then add a line to pass the test in the function above
5471

5572
// Case 4: Identify Straight Angles:
5673
// When the angle is exactly 180 degrees,
5774
// Then the function should return "Straight angle"
5875
// ====> write your test here, and then add a line to pass the test in the function above
76+
const straight = getAngleType(180);
77+
assertEquals(straight, "Straight angle");
5978

6079
// Case 5: Identify Reflex Angles:
6180
// When the angle is greater than 180 degrees and less than 360 degrees,
6281
// Then the function should return "Reflex angle"
63-
// ====> write your test here, and then add a line to pass the test in the function above
82+
// ====> write your test here, and then add a line to pass the test in the function above const reflex = getAngleType(270);
83+
const reflex = getAngleType(270);
84+
assertEquals(reflex, "Reflex angle");
85+
86+
console.assert(reflex === "Reflex angle", `Expected ${reflex} to equal Reflex angle`);

0 commit comments

Comments
 (0)