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