ggeorgiev88

areaCalculation

Nov 8th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function areaCalculation(input){
  2.     let figure = input[0];
  3.  
  4.     if ( figure === "square" ){
  5.         let a = Number(input[1]);
  6.         console.log((a * a).toFixed(3));
  7.     }
  8.  
  9.     else if ( figure === "rectangle"){
  10.         let a = Number(input[1]);
  11.         let b = Number(input[2]);
  12.         console.log((a * b).toFixed(3));
  13.     }
  14.  
  15.     else if ( figure === "circle"){
  16.         let r = Number(input[1]);
  17.         console.log((Math.PI * Math.pow(r , 2)).toFixed(3));
  18.     }
  19.    
  20.     else ( figure === "triangle")
  21.         let a = Number(input[1]);
  22.         let b = Number(input[2]);
  23.         console.log(((a * b) / 2).toFixed(3) );
  24.  
  25.  
  26.    
  27.  
  28.  
  29.  
  30.  
  31. }
  32. //areaCalculation(["square", "5"]);
  33. //areaCalculation(["rectangle", "7", "2.5"]);
  34. areaCalculation(["circle", "6"]);
  35. //areaCalculation(["triangle", "4.5", "20"]);
Add Comment
Please, Sign In to add comment