vikkktor

Data Types and Var_Cone

Oct 12th, 2021 (edited)
718
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //--------------------------------------
  2. // Write a function to calculate a cone’s volume and total surface area by given height and radius at the base.
  3. // The input comes as two number arguments. The first element is the cone’s radius and the second is its height.
  4. // The output should be printed to the console on a new line for every result.
  5. // The result should be formatted to the fourth decimal point
  6. //--------------------------------------
  7.  
  8. function cone(arg1, arg2) {
  9.     let radius = arg1
  10.     let height = arg2
  11.  
  12.     function coneVolume(radius, height) {
  13.         let volume = (Math.PI * Math.pow(radius, 2) * height) / 3
  14.         return volume
  15.     }
  16.  
  17.     const slantHeight = function(radius, height) {
  18.         let slantH = Math.sqrt(Math.pow(radius,2) + Math.pow(height,2))
  19.         return slantH
  20.     }
  21.  
  22.     const lateralSurfaceArea = function(radius,slantH) {
  23.         let lateralS = Math.PI * radius * slantH
  24.         return lateralS
  25.     }
  26.    
  27.     const baseSurfaceArea = function(radius) {
  28.         let baseSur = Math.PI * Math.pow(radius,2)
  29.         return baseSur
  30.     }
  31.  
  32.     const totalSurface = function(lateralS,baseSur) {
  33.         let totalS = Number(lateralS) + Number(baseSur)
  34.         return totalS
  35.     }
  36.  
  37.  
  38.     console.log("volume = " + coneVolume(radius, height).toFixed(4))
  39.     let slantH = slantHeight(radius, height)
  40.     let lateralS = lateralSurfaceArea(radius,slantH).toFixed(4)
  41.     let baseSur = baseSurfaceArea(radius)
  42.     console.log("area = " + totalSurface(lateralS,baseSur).toFixed(4))
  43. }
  44. cone(3.3, 7.8)
RAW Paste Data