Common Computer Science References
At the end of this lesson, you will be able to:
understand and use complex if ... then statement
what decision structures
nil
create a program that lets the user input 3 lengths of a triangle and you will tell them what kind:
equilateral triangle
isosceles triangle
scalene triangle
NOTE: we also need to ensure the sum of all the angles = 180°
look at this Repl.it to see how to do that
(or code below)
HINT: the easiest way right now is probably to do an If ... Else if ... Else if ... Else if ... Else; and check if it really a triangle first!
do the above program in PHP
const lengthAString = prompt("Enter length A of the triangle (mm):")
const lengthBString = prompt("Enter length A of the triangle (mm):")
const lengthCString = prompt("Enter length A of the triangle (mm):")
const lengthA = parseFloat(lengthAString)
const lengthB = parseFloat(lengthBString)
const lengthC = parseFloat(lengthCString)
// using the cosine law
const angleA = Math.acos((lengthB**2 + lengthC**2 - lengthA**2) / (2 * lengthB * lengthC)) * (180/Math.PI)
const angleB = Math.acos((lengthC**2 + lengthA**2 - lengthB**2) / (2 * lengthC * lengthA)) * (180/Math.PI)
const angleC = Math.acos((lengthA**2 + lengthB**2 - lengthC**2) / (2 * lengthA * lengthB)) * (180/Math.PI)
const sumOfAngles = Number((angleA).toFixed(2)) + Number((angleB).toFixed(2)) + Number((angleC).toFixed(2))
console.log(angleA)
console.log(angleB)
console.log(angleC)
console.log(sumOfAngles)