logo image

JavaScript program to calculate triangle area


Following program shows you how to calculate triangle area. This program gets triangle base and height from user and calculates area and prints it using following formula Area = base X height / 2

var triangleBase = parseInt(prompt("Enter the base of triangle:"));
var triangleHeight = parseInt(prompt("Enter the height of triangle:"));
var areaOfTriangle = (triangleBase * triangleHeight) / 2;
console.log("Area of triangle is: " + areaOfTriangle);


Enter the base of triangle:
Enter the height of triangle:
Area of triangle is: 3.0