Write a JavaScript program to calculate Area of atrapezoid
Equation: Area = (top side + bottom side) * height / 2
1. Use prompt() function to take top side, bottom side, and heightvalues from user
2. For validation, if user did not put in a number, your programmust send out
3. “Input must be number” error message using alert()function.
4. If user put in all numbers, use alert() function to outputcorrect answer
Solution
Java Script program:
var top = parseInt(prompt(“Enter top side of Trapazoid :”));
var bottom = parseInt(prompt(“Enter bottom side of Trapazoid :”));
var height = parseInt(prompt(“Enter height of Trapazoid :”));
var area = (top+bottom)*height/2;
if(isNaN(top)|| isNaN(bottom)||isNaN(height))
alert(“Input must be
OR
OR