Advertisement
mark79

New House

Oct 28th, 2019
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function newHouse(input) {
  2.     let flowerType = input.shift();
  3.     let flowerCount = Number(input.shift());
  4.     let budget = Number(input.shift());
  5.  
  6.     let flowerPrice = 0;
  7.     switch (flowerType) {
  8.         case "Roses":
  9.             flowerPrice = flowerCount > 80 ? 5.00 * 0.90 : 5.00;
  10.             // if (flowerCount > 80) {
  11.             //     flowerPrice = 5.00 * 0.90;
  12.             // } else {
  13.             //     flowerPrice = 5.00;
  14.             // }
  15.             break;
  16.         case "Dahlias":
  17.             flowerPrice = flowerCount > 90 ? 3.80 * 0.85 : 3.80;
  18.             break;
  19.         case "Tulips":
  20.             flowerPrice = flowerCount > 80 ? 2.80 * 0.85 : 2.80;
  21.             break;
  22.         case "Narcissus":
  23.             flowerPrice = flowerCount < 120 ? 3.00 * 1.15 : 3.00;
  24.             break;
  25.         case "Gladiolus":
  26.             flowerPrice = flowerCount < 80 ? 2.50 * 1.20 : 2.50;
  27.             break;
  28.     }
  29.  
  30.     let totalPrice = flowerCount * flowerPrice;
  31.  
  32.     let result = Math.abs(budget - totalPrice);
  33.     if (totalPrice > budget) {
  34.         console.log(`Not enough money, you need ${result.toFixed(2)} leva more.`);
  35.     } else {
  36.         console.log(`Hey, you have a great garden with ${flowerCount} ${flowerType} and ${result.toFixed(2)} leva left.`);
  37.     }
  38. }
  39.  
  40. newHouse(["Roses", 55, 250]);
  41. newHouse(["Tulips",88,260]);
  42. newHouse(["Narcissus",119,360]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement