vikkktor

Data Types and Var_triangleArea

Oct 12th, 2021
865
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //--------------------------------------------
  2. //Write a function that calculates a triangle’s area by its 3 sides.
  3. //The input comes as three number arguments, representing one side of a triangle.
  4. //The output should be printed to the console.
  5. //--------------------------------------------
  6.  
  7. function triangleArea(sideA, sideB, sideC) {
  8.  
  9.     let a = sideA
  10.     let b = sideB
  11.     let c = sideC
  12.  
  13.     let s = (a + b + c) / 2
  14.     let area = Math.sqrt(s * (s-a) * (s-b) * (s-c))
  15.  
  16.     console.log(area)
  17.  
  18. }
RAW Paste Data