JavaScript program to calculate trapezoid area


Following program shows you how to calculate trapezoid area.
This program gets trapezoid base and height from user and calculates area and prints it using following formula
Area = (base1 + base2) X height /2

var trapezoidBase1 = parseInt(prompt("Please enter base1 of trapezoid:"));
var trapezoidBase2 = parseInt(prompt("Please enter base2 of trapezoid:"));
var trapezoidHeight = parseInt(prompt("Please enter height of trapezoid:"));
var areaOfTrapezoid = (trapezoidBase1 + trapezoidBase2) * trapezoidHeight / 2;
console.log("Area of trapezoid is: " + areaOfTrapezoid);

Output:

Please enter base1 of trapezoid:
5
Please enter base2 of trapezoid:
8
Please enter height of trapezoid:
3
Area of trapezoid is: 19.5