Advertisement
at90

Untitled

May 16th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. function calculateAreaOfFigures(input) {
  2. let figure = input[0];
  3. let area;
  4. if (figure === 'square') {
  5. let a = Number(input[1]);
  6. area = a * a;
  7. } else if (figure === 'rectangle') {
  8. let a = Number(input[1]);
  9. let b = Number(input[2]);
  10. area = a * b;
  11. } else if (figure === 'circle') {
  12. let r = Number(input[1]);
  13. area = Math.PI * r * r;
  14. } else {
  15. let b = Number(input[1]);
  16. let h = Number(input[2]);
  17. area = 0.5 * b * h;
  18. }
  19. console.log(area.toFixed(3));
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement