JavaScript: Find the types of a specified angle
JavaScript Basic: Exercise-86 with Solution
Find Type of Given Angle
Write a JavaScript program to find the types of a given angle.
Types of angles:
• Acute angle: An angle between 0 and 90 degrees.
• Right angle: An 90 degree angle.
• Obtuse angle: An angle between 90 and 180 degrees.
• Straight angle: A 180 degree angle.
Visual Presentation:
Sample Solution:
JavaScript Code:
// Function to determine the type of angle based on its measure
function angle_Type(angle) {
if(angle < 90) {
return "Acute angle."; // Return this message if the angle is less than 90 degrees
}
if(angle === 90) {
return "Right angle."; // Return this message if the angle is exactly 90 degrees
}
if(angle < 180) {
return "Obtuse angle."; // Return this message if the angle is less than 180 degrees but not 90 degrees
}
return "Straight angle."; // Return this message if the angle is exactly 180 degrees
}
// Example usage
console.log(angle_Type(47)); // Acute angle.
console.log(angle_Type(90)); // Right angle.
console.log(angle_Type(145)); // Obtuse angle.
console.log(angle_Type(180)); // Straight angle.
Output:
Acute angle. Right angle. Obtuse angle. Straight angle.
Live Demo:
See the Pen javascript-basic-exercise-85 by w3resource (@w3resource) on CodePen.
Flowchart:
ES6 Version:
// Function to determine the type of angle based on its measure
const angle_Type = (angle) => {
if (angle < 90) {
return "Acute angle."; // Return this message if the angle is less than 90 degrees
}
if (angle === 90) {
return "Right angle."; // Return this message if the angle is exactly 90 degrees
}
if (angle < 180) {
return "Obtuse angle."; // Return this message if the angle is less than 180 degrees but not 90 degrees
}
return "Straight angle."; // Return this message if the angle is exactly 180 degrees
};
// Example usage
console.log(angle_Type(47)); // Acute angle.
console.log(angle_Type(90)); // Right angle.
console.log(angle_Type(145)); // Obtuse angle.
console.log(angle_Type(180)); // Straight angle.
Improve this sample solution and post your code through Disqus.
Previous: JavaScript code to divide an given array of positive integers into two parts.
Next: JavaScript program to check whether two arrays of integers and same length are similar or not.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/javascript-exercises/javascript-basic-exercise-86.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics