Here's a code snippet that calculates the volume of a sphere in TypeScript:
index.ts274 chars10 lines
In this code, we defined a function called calculateSphereVolume
that takes the radius of the sphere as a parameter and returns the volume of the sphere. We then call this function with a radius of 5 and log the result to the console.
The formula for calculating the volume of a sphere is V = (4/3) * π * r^3, where r is the radius of the sphere. We use this formula in our TypeScript function to calculate the volume of the sphere.
The Math.PI
property represents the value of pi, and Math.pow()
is used to raise the radius to the power of 3. The volume is then returned by the function.
gistlibby LogSnag