Javascript program to enter the base and height of a triangle and find its area
ADVERTISEMENTS
Javascript program to enter the base and height of a triangle and find its area. There are you will learn how to find the area of a triangle by using the base & height of the triangle in javascript language.
Formula:
a = (b + h) / 2
Where:
a = area
b = base
h = height
Let us understand this example through javascript program:
/* Javascript program to find the area of a triangle if base and height are given */
<script type="text/javascript">
var b, h, a;
// b = base
// h = height
// a = area
b = 32;
h = 8;
// Calculate area of the triangle
a = ((b * h) / 2);
document.write("Area of the triangle = " + a + " sq. units");
</script>
Output Screen:
Area of the triangle = 128 sq. units