find the volume of a pyramid in javascript

To find the volume of a pyramid in JavaScript, we can use the formula:

index.tsx
V = (1/3) * b * h
18 chars
2 lines

where V is the volume of the pyramid, b is the base of the pyramid, and h is the height of the pyramid.

Here's the JavaScript code to calculate the volume of a pyramid:

index.tsx
function pyramidVolume(base, height) {
  let volume = (1/3) * base * height;
  return volume;
}

// Example usage:
let base = 10;
let height = 5;
let volume = pyramidVolume(base, height);
console.log("The volume of the pyramid is: " + volume);
244 chars
11 lines

In this example, we have defined a function pyramidVolume that takes in the base and height of a pyramid and returns the volume of the pyramid. We have also included an example usage of the function.

gistlibby LogSnag