find the surface area of a sphere in javascript

To find the surface area of a sphere in JavaScript, we can use the formula:

surface area = 4 * π * r^2

Where r is the radius of the sphere.

Here's an example code snippet that calculates the surface area of a sphere with a given radius using the formula above:

index.tsx
const radius = 5;

const surfaceArea = 4 * Math.PI * Math.pow(radius, 2);

console.log(`The surface area of a sphere with radius ${radius} is ${surfaceArea}.`);
161 chars
6 lines

In this example, we first define the radius of the sphere as 5. Then, we use the Math.pow method to raise the radius to the power of 2 to get the area of the circle. Finally, we log the surface area to the console using a template literal.

gistlibby LogSnag