find the surface area of a triangular prism in javascript

To find the surface area of a triangular prism in JavaScript, you can use the following formula:

Surface Area = 2 * baseArea + lateralArea

where baseArea is the area of the base, and lateralArea is the combined area of all the lateral faces of the prism.

Here's an implementation in JavaScript:

index.tsx
function surfaceAreaTriangularPrism(baseWidth, baseLength, height, sideLength) {
  const baseArea = 0.5 * baseWidth * baseLength; // area of the base triangle
  const perimeter = 3 * sideLength; // perimeter of the base triangle
  const apothem = height; // length of the apothem of the base triangle
  
  const lateralArea = perimeter * apothem; // combined area of all lateral faces
  
  return 2 * baseArea + lateralArea; // total surface area of the prism
}
462 chars
10 lines

You can then call this function with the dimensions of the triangular prism to get the surface area:

index.tsx
const surfaceArea = surfaceAreaTriangularPrism(4, 5, 6, 3); // returns 97.39
77 chars
2 lines

gistlibby LogSnag