Advertisement
dimipan80

Tree or House

Nov 9th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Write a JavaScript function treeHouseCompare(arr) that accepts the following parameters:
  2. integers a and b. The function compares the area of the house and the area of the tree (Figure 1)
  3. and returns the name of the figure with bigger area (house or tree) and the value of the area.
  4. Write JS program treehouse.js that compares a few houses and trees. */
  5.  
  6. "use strict";
  7.  
  8. function treeHouseCompare(arr) {
  9.     var areaTree = arr[1] * arr[1] / 3 + Math.PI * (arr[1] * 2) / 3 * (arr[1] * 2) / 3;
  10.     var areaHouse = arr[0] * arr[0] + arr[0] * (arr[0] / 3);
  11.     if (areaTree > areaHouse) {
  12.         console.log('tree/' + areaTree.toFixed(2));
  13.     } else if (areaHouse > areaTree) {
  14.         console.log('house/' + areaHouse.toFixed(2));
  15.     }
  16. }
  17.  
  18. treeHouseCompare([3, 2]);
  19. treeHouseCompare([3, 3]);
  20. treeHouseCompare([4, 5]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement