TZinovieva

Flowers 100/100

May 25th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function flowers(input) {
  2.     let chrisanthemumQty = Number(input[0]);
  3.     let rosesQty = Number(input[1]);
  4.     let tulipsQty = Number(input[2]);
  5.     let season = input[3];
  6.     let holiday = input[4];
  7.  
  8.     let chrisanthemumPrice = 0;
  9.     let rosesPrice = 0;
  10.     let tulipsPrice = 0;
  11.    
  12.     if (holiday === "N") {
  13.     switch (season) {
  14.         case "Spring":
  15.         case "Summer":
  16.             chrisanthemumPrice = chrisanthemumQty * 2;
  17.             rosesPrice = rosesQty * 4.10;
  18.             tulipsPrice = tulipsQty * 2.50;
  19.             break;
  20.         case "Autumn":
  21.         case "Winter":
  22.             chrisanthemumPrice = chrisanthemumQty * 3.75;
  23.             rosesPrice = rosesQty * 4.50;
  24.             tulipsPrice = tulipsQty * 4.15;
  25.             break;
  26.     }
  27. }
  28.     if (holiday === "Y") {
  29.         switch (season) {
  30.         case "Spring":
  31.         case "Summer":
  32.             chrisanthemumPrice = (chrisanthemumQty * 2) * 1.15;
  33.             rosesPrice = (rosesQty * 4.10) * 1.15;
  34.             tulipsPrice = (tulipsQty * 2.50) * 1.15;
  35.             break;
  36.         case "Autumn":
  37.         case "Winter":
  38.             chrisanthemumPrice = (chrisanthemumQty * 3.75 * 1.15);
  39.             rosesPrice = (rosesQty * 4.50) * 1.15;
  40.             tulipsPrice = (tulipsQty * 4.15) * 1.15;
  41.             break;
  42.         }
  43.     }
  44.     let bouquetPrice = chrisanthemumPrice + rosesPrice + tulipsPrice;
  45.     if (season === "Spring" && tulipsQty > 7) {
  46.         bouquetPrice = bouquetPrice * 0.95;
  47.     }
  48.     if (season === "Winter" && rosesQty >= 10) {
  49.         bouquetPrice = bouquetPrice * 0.90;
  50.     }
  51.     if ((chrisanthemumQty + rosesQty + tulipsQty) > 20) {
  52.         bouquetPrice = bouquetPrice * 0.80;
  53.     }
  54.     console.log((bouquetPrice + 2).toFixed(2));
  55. }
Advertisement
Add Comment
Please, Sign In to add comment