Skip to content

Commit b5de08b

Browse files
committed
build up getAngleType case by case
1 parent 8f3d6cf commit b5de08b

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,19 @@ function getAngleType(angle) {
1111
if (angle === 90) {
1212
return "Right angle";
1313
}
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.
14+
if (angle < 90 && angle > 0) {
15+
return "Acute angle";
16+
}
17+
if (angle > 90 && angle < 180) {
18+
return "Obtuse angle";
19+
}
20+
if (angle === 180) {
21+
return "Straight angle";
22+
}
23+
if (angle > 180 && angle < 360) {
24+
return "Reflex angle";
25+
}
26+
return "Invalid angle";
1627
}
1728

1829
// The line below allows us to load the getAngleType function into tests in other files.
@@ -50,14 +61,33 @@ assertEquals(acute, "Acute angle");
5061
// When the angle is greater than 90 degrees and less than 180 degrees,
5162
// Then the function should return "Obtuse angle"
5263
const obtuse = getAngleType(120);
53-
// ====> write your test here, and then add a line to pass the test in the function above
64+
assertEquals(obtuse, "Obtuse angle");
5465

5566
// Case 4: Identify Straight Angles:
5667
// When the angle is exactly 180 degrees,
5768
// Then the function should return "Straight angle"
5869
// ====> write your test here, and then add a line to pass the test in the function above
59-
70+
const straight = getAngleType(180);
71+
assertEquals(straight, "Straight angle");
6072
// Case 5: Identify Reflex Angles:
6173
// When the angle is greater than 180 degrees and less than 360 degrees,
6274
// 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
75+
// ====> write your test here, and then add a line to pass the test in the function above
76+
const reflex = getAngleType(270);
77+
assertEquals(reflex, "Reflex angle");
78+
79+
let angle = 120;
80+
console.log(angle + " degrees is a " + getAngleType(angle));
81+
angle = 45;
82+
console.log(angle + " degrees is a " + getAngleType(angle));
83+
angle = 90;
84+
console.log(angle + " degrees is a " + getAngleType(angle));
85+
angle = 180;
86+
console.log(angle + " degrees is a " + getAngleType(angle));
87+
angle = 270;
88+
console.log(angle + " degrees is a " + getAngleType(angle));
89+
angle = -10;
90+
console.log(angle + " degrees is a " + getAngleType(angle));
91+
angle = 400;
92+
console.log(angle + " degrees is a " + getAngleType(angle));
93+
// Case 6: Handle Invalid Angles:

0 commit comments

Comments
 (0)