|
7 | 7 | // - "Straight angle" for exactly 180° |
8 | 8 | // - "Reflex angle" for angles greater than 180° and less than 360° |
9 | 9 | // - "Invalid angle" for angles outside the valid range. |
10 | | - |
11 | 10 | // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) |
12 | 11 |
|
13 | | -// Acceptance criteria: |
14 | | -// After you have implemented the function, write tests to cover all the cases, and |
15 | | -// execute the code to ensure all tests pass. |
16 | | - |
17 | 12 | function getAngleType(angle) { |
18 | | - // TODO: Implement this function |
| 13 | + if (angle > 0 && angle < 90) { |
| 14 | + return "Acute angle"; |
| 15 | + } else if (angle === 90) { |
| 16 | + return "Right angle"; |
| 17 | + } else if (angle > 90 && angle < 180) { |
| 18 | + return "Obtuse angle"; |
| 19 | + } else if (angle === 180) { |
| 20 | + return "Straight angle"; |
| 21 | + } else if (angle > 180 && angle < 360) { |
| 22 | + return "Reflex angle"; |
| 23 | + } else { |
| 24 | + return "Invalid angle"; |
| 25 | + } |
19 | 26 | } |
20 | 27 |
|
21 | 28 | // The line below allows us to load the getAngleType function into tests in other files. |
22 | | -// This will be useful in the "rewrite tests with jest" step. |
23 | 29 | module.exports = getAngleType; |
24 | | - |
25 | | -// This helper function is written to make our assertions easier to read. |
26 | | -// If the actual output matches the target output, the test will pass |
27 | | -function assertEquals(actualOutput, targetOutput) { |
28 | | - console.assert( |
29 | | - actualOutput === targetOutput, |
30 | | - `Expected ${actualOutput} to equal ${targetOutput}` |
31 | | - ); |
32 | | -} |
33 | | - |
34 | | -// TODO: Write tests to cover all cases, including boundary and invalid cases. |
35 | | -// Example: Identify Right Angles |
36 | | -const right = getAngleType(90); |
37 | | -assertEquals(right, "Right angle"); |
0 commit comments