javascript program to calculate the area of triangle
Answers
Answered by
0
program to calculate the area of the triangle:
source code:
const baseVal = prompt('Enter the base of a triangle: ');
const heightVal = prompt('Enter the height of a triangle: ');
// calculate the area
const areaVal = (baseVal * heightVal) / 2;
console.log(
`The area of the triangle is ${areaVal}`
);
Explanation:
we know that,
the area of the triangle = 1/2 x base x height
the first statement takes the input of the base of the triangle, and in the following statement, the height value is taken as input.
having the value of base and height, the variable areaVal calculates the area of the triangle and, using the console.log, the area of the triangle is displayed.
#SPJ1
Similar questions