Question: Write a JavaScript function to classify a triangle as equilateral ( all sides equal ) , isosceles ( any two sides equal ) or scalene

Write a JavaScript function to classify a triangle as equilateral (all sides equal), isosceles (any two sides equal) or scalene (all sides different lengths). To make the code clearer, you must use complex conditions. This function has been partially completed for you. Complete the complex conditions so that the appropriate classification is in the variable answer.
function classifyTriangle (){
//Declare variables
var a, b, c, answer;
//Read inputs - three sides a,b,c
a= parseFloat (document.getElementById ('side1'). value);
b = parsefloat (document.getelementById ('side2'). value);
c= parsefloat (document.getElementById('side3'). value);
//Process - find correct classification and put it in "answer"
//Equilateral case first: COMPLETE
if (
answer = 'Equilateral';
}
//Scalene case next: coMPLETE
else if (
answer = 'Scalene';
}
//Everything left has to be Isosceles case:
else {
answer = 'Isosceles';
}
//Display output
document.getElementById ("output'). innerHTML =
'Classification = 'tanswer;
 Write a JavaScript function to classify a triangle as equilateral (all

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!