find the area of a trapezoid in javascript

Here's the code to find the area of a trapezoid in JavaScript using the mathematical formula:

index.tsx
function calculateTrapezoidArea(base1, base2, height) {
  // calculate the area using the mathematical formula
  const area = ((base1 + base2) * height) / 2;
  return area;
}

// Example usage:
const base1 = 5;
const base2 = 7;
const height = 9;
const area = calculateTrapezoidArea(base1, base2, height);
console.log(area); // Output: 54
338 chars
13 lines

In this code, the calculateTrapezoidArea() function takes in the two bases and the height of the trapezoid as parameters and calculates the area using the formula ((base1 + base2) * height) / 2. The result is then returned by the function.

We then have an example usage of the function, where we define the values of base1, base2, and height and call the calculateTrapezoidArea() function with these values. The result is stored in the area variable and then printed to the console using console.log().

gistlibby LogSnag