Skip to content

Commit e59bc4c

Browse files
authored
Implement getAngleType function and add tests
Implemented the getAngleType function to determine angle types and added tests for various cases.
1 parent 3372770 commit e59bc4c

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,22 @@
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+
}
21+
if (angle === 90) {
22+
return "Right angle";
23+
}
24+
if (angle > 90 && angle < 180) {
25+
return "Obtuse angle";
26+
}
27+
if (angle === 180) {
28+
return "Straight angle";
29+
}
30+
if (angle > 180 && angle < 360) {
31+
return "Reflex angle";
32+
}
33+
return "Invalid angle";
1934
}
2035

2136
// The line below allows us to load the getAngleType function into tests in other files.
@@ -35,3 +50,24 @@ function assertEquals(actualOutput, targetOutput) {
3550
// Example: Identify Right Angles
3651
const right = getAngleType(90);
3752
assertEquals(right, "Right angle");
53+
54+
const acute = getAngleType(45);
55+
assertEquals(acute, "Acute angle");
56+
57+
const obtuse = getAngleType(120);
58+
assertEquals(obtuse, "Obtuse angle");
59+
60+
const straight = getAngleType(180);
61+
assertEquals(straight, "Straight angle");
62+
63+
const reflex = getAngleType(270);
64+
assertEquals(reflex, "Reflex angle");
65+
66+
const invalidZero = getAngleType(0);
67+
assertEquals(invalidZero, "Invalid angle");
68+
69+
const invalidNegative = getAngleType(-45);
70+
assertEquals(invalidNegative, "Invalid angle");
71+
72+
const invalidOver = getAngleType(361);
73+
assertEquals(invalidOver, "Invalid angle");

0 commit comments

Comments
 (0)