Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,49 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

function getAngleType(angle) {
//function getAngleType(angle) {
// TODO: Implement this function

// Implement a function getAngleType
function getAngleType(angle) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function assumes the input is always a valid number. You may want to guard against non-number values (e.g. "90", null, NaN) to avoid unexpected behaviour.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅


if (typeof angle !== "number" || !Number.isFinite(angle)) {
return "Invalid angle";
}


if (angle <= 0 || angle >= 360) {
return "Invalid angle";
}


if (angle < 90) return "Acute angle";
if (angle === 90) return "Right angle";
if (angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
return "Reflex angle";
}

// The line below allows us to load the getAngleType function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getAngleType;

// This helper function is written to make our assertions easier to read.
// If the actual output matches the target output, the test will pass
function assertEquals(actualOutput, targetOutput) {
module.exports = getAngleType;


function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
// ===> TESTS
console.log("Testing Acute angles...");
assertEquals(getAngleType(1), "Acute angle");


console.log("Testing input validation...");
assertEquals(getAngleType("90"), "Invalid angle");
assertEquals(getAngleType(null), "Invalid angle");
assertEquals(getAngleType(NaN), "Invalid angle");
assertEquals(getAngleType(Infinity), "Invalid angle");

console.log("\n✅ All tests completed successfully!");