← Back to challenges

Volume of a Spherical Shell

JavaScriptHardmathnumbersgeometry

Instructions

The volume of a spherical shell is the difference between the enclosed volume of the outer sphere and the enclosed volume of the inner sphere:

Volume of Inner Sphere Formula

Create a function that takes r1 and r2 as arguments and returns the volume of a spherical shell rounded to the nearest thousandth.

Spherical Shell Image

Examples

volShell(3, 3) ➞ 0

volShell(7, 2) ➞ 1403.245

volShell(3, 800) ➞ 2144660471.753

Notes

The inputs are always positive numbers. r1 could be the inner radius or the outer radius, don't return a negative number.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.