Advertisement
Liliana797979

viarno reshenie na new house

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