1- // Implement a function getAngleType
2- // Build up your function case by case, writing tests as you go
3- // The first test and case is written for you. The next case has a test, but no code.
4- // Execute this script in your terminal
5- // node 1-get-angle-type.js
6- // The assertion error will tell you what the expected output is
7- // Write the code to pass the test
8- // Then, write the next test! :) Go through this process until all the cases are implemented
9-
101function getAngleType ( angle ) {
112 if ( angle === 90 ) {
123 return "Right angle" ;
134 }
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.
5+ if ( angle < 90 ) {
6+ return "Acute angle" ;
7+ }
8+ if ( angle > 90 && angle < 180 ) {
9+ return "Obtuse angle" ;
10+ }
11+ if ( angle === 180 ) {
12+ return "Straight angle" ;
13+ }
14+ if ( angle > 180 && angle < 360 ) {
15+ return "Reflex angle" ;
16+ }
1617}
17-
1818// The line below allows us to load the getAngleType function into tests in other files.
1919// This will be useful in the "rewrite tests with jest" step.
2020module . exports = getAngleType ;
@@ -28,12 +28,6 @@ function assertEquals(actualOutput, targetOutput) {
2828 ) ;
2929}
3030
31- // Acceptance criteria:
32-
33- // Given an angle in degrees,
34- // When the function getAngleType is called with this angle,
35- // Then it should:
36-
3731// Case 1: Identify Right Angles:
3832// When the angle is exactly 90 degrees,
3933// Then the function should return "Right angle"
@@ -50,14 +44,16 @@ assertEquals(acute, "Acute angle");
5044// When the angle is greater than 90 degrees and less than 180 degrees,
5145// Then the function should return "Obtuse angle"
5246const obtuse = getAngleType ( 120 ) ;
53- // ====> write your test here, and then add a line to pass the test in the function above
47+ assertEquals ( obtuse , "Obtuse angle" ) ;
5448
5549// Case 4: Identify Straight Angles:
5650// When the angle is exactly 180 degrees,
5751// Then the function should return "Straight angle"
58- // ====> write your test here, and then add a line to pass the test in the function above
52+ const straight = getAngleType ( 180 ) ;
53+ assertEquals ( straight , "Straight angle" ) ;
5954
6055// Case 5: Identify Reflex Angles:
6156// When the angle is greater than 180 degrees and less than 360 degrees,
6257// 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
58+ const reflex = getAngleType ( 250 ) ;
59+ assertEquals ( reflex , "Reflex angle" ) ;
0 commit comments