audipower

weddingDecoratin

Mar 1st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function weddingDecoration(input) {
  2.  
  3.     let budget = Number(input.shift());
  4.     let decoration = input.shift();
  5.     let countBaloons = 0;
  6.     let countFlowers = 0;
  7.     let countCandles = 0;
  8.     let countRibbon = 0;
  9.     let moneyLeft = budget;
  10.  
  11.     while (decoration !== "stop") {
  12.         let numberOfItems = Number(input.shift());
  13.         if (decoration == "balloons") {
  14.             moneyLeft -= numberOfItems * 0.1;
  15.             countBaloons += numberOfItems
  16.         } else if (decoration == "flowers") {
  17.             moneyLeft -= numberOfItems * 1.5;
  18.             countFlowers += numberOfItems;
  19.         } else if (decoration == "candles") {
  20.             moneyLeft -= numberOfItems * 0.5;
  21.             countCandles += numberOfItems;
  22.         } else if (decoration == "ribbon") {
  23.             moneyLeft -= numberOfItems * 2;
  24.             countRibbon += numberOfItems;
  25.         }
  26.         if (moneyLeft <= 0) {
  27.             console.log("All money is spent!");
  28.             break;
  29.         }
  30.  
  31.         decoration = input.shift();
  32.        
  33.     }
  34.     if (decoration == "stop") {
  35.         let spendMoney = budget - moneyLeft;
  36.         console.log(`Spend money: ${spendMoney.toFixed(2)}`);
  37.         console.log(`Money left: ${moneyLeft.toFixed(2)}`);
  38.        
  39.     }
  40.     console.log(`Purchased decoration is ${countBaloons} balloons, ${countRibbon} m ribbon, ${countFlowers} flowers and ${countCandles} candles.`);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment