Advertisement
Didart

New House

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