JavaScript program to calculate trapezoid area

Views: 442   

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);


Please enter base1 of trapezoid:
Please enter base2 of trapezoid:
Please enter height of trapezoid:
Area of trapezoid is: 19.5
On By