Advertisement
Didart

Area Of Figures

Mar 5th, 2022
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function areaOfFigures(input) {
  2.     let type = input[0];
  3.  
  4.     let result = 0;
  5.     if (type === "square") {
  6.         let a = Number(input[1]);
  7.         result = a * a;
  8.     } else if (type === "rectangle") {
  9.         let a = Number(input[1]);
  10.         let b = Number(input[2]);
  11.         result = a * b;
  12.     } else if (type === "circle") {
  13.         let radius = Number(input[1]);
  14.         result = Math.pow(radius, 2) * Math.PI;
  15.     } else {
  16.         let a = Number(input[1]);
  17.         let height = Number(input[2]);
  18.         result = a * height / 2;
  19.     }
  20.     console.log(result.toFixed(3));
  21. }
  22.  
  23. areaOfFigures(["square", "5"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement