Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------
- // Write a function to calculate a cone’s volume and total surface area by given height and radius at the base.
- // The input comes as two number arguments. The first element is the cone’s radius and the second is its height.
- // The output should be printed to the console on a new line for every result.
- // The result should be formatted to the fourth decimal point
- //--------------------------------------
- function cone(arg1, arg2) {
- let radius = arg1
- let height = arg2
- function coneVolume(radius, height) {
- let volume = (Math.PI * Math.pow(radius, 2) * height) / 3
- return volume
- }
- const slantHeight = function(radius, height) {
- let slantH = Math.sqrt(Math.pow(radius,2) + Math.pow(height,2))
- return slantH
- }
- const lateralSurfaceArea = function(radius,slantH) {
- let lateralS = Math.PI * radius * slantH
- return lateralS
- }
- const baseSurfaceArea = function(radius) {
- let baseSur = Math.PI * Math.pow(radius,2)
- return baseSur
- }
- const totalSurface = function(lateralS,baseSur) {
- let totalS = Number(lateralS) + Number(baseSur)
- return totalS
- }
- console.log("volume = " + coneVolume(radius, height).toFixed(4))
- let slantH = slantHeight(radius, height)
- let lateralS = lateralSurfaceArea(radius,slantH).toFixed(4)
- let baseSur = baseSurfaceArea(radius)
- console.log("area = " + totalSurface(lateralS,baseSur).toFixed(4))
- }
- cone(3.3, 7.8)
Advertisement
Add Comment
Please, Sign In to add comment