find the surface area of a cone in javascript

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

index.tsx
surface area = π * r * (r + s)
31 chars
2 lines

where r is the radius of the base of the cone, s is the slant height of the cone, and π is pi (approximately equal to 3.14159).

Here's the JavaScript function to calculate the surface area of a cone:

index.tsx
function coneSurfaceArea(radius, height) {
  const slantHeight = Math.sqrt(radius * radius + height * height);
  const surfaceArea = Math.PI * radius * slantHeight + Math.PI * radius * radius;
  return surfaceArea;
}
217 chars
6 lines

You can call this function and pass in the radius and height of the cone as arguments to get the surface area. For example:

index.tsx
const radius = 5;
const height = 10;
const surfaceArea = coneSurfaceArea(radius, height);
console.log(surfaceArea); // 235.619 + (approximately)
145 chars
5 lines

Note that the value of surfaceArea will be in square units (e.g. square feet or square meters) since it's a measure of area.

gistlibby LogSnag