Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function weddingDecoration(input) {
- let budget = Number(input.shift());
- let decoration = input.shift();
- let countBaloons = 0;
- let countFlowers = 0;
- let countCandles = 0;
- let countRibbon = 0;
- let moneyLeft = budget;
- while (decoration !== "stop") {
- let numberOfItems = Number(input.shift());
- if (decoration == "balloons") {
- moneyLeft -= numberOfItems * 0.1;
- countBaloons += numberOfItems
- } else if (decoration == "flowers") {
- moneyLeft -= numberOfItems * 1.5;
- countFlowers += numberOfItems;
- } else if (decoration == "candles") {
- moneyLeft -= numberOfItems * 0.5;
- countCandles += numberOfItems;
- } else if (decoration == "ribbon") {
- moneyLeft -= numberOfItems * 2;
- countRibbon += numberOfItems;
- }
- if (moneyLeft <= 0) {
- console.log("All money is spent!");
- break;
- }
- decoration = input.shift();
- }
- if (decoration == "stop") {
- let spendMoney = budget - moneyLeft;
- console.log(`Spend money: ${spendMoney.toFixed(2)}`);
- console.log(`Money left: ${moneyLeft.toFixed(2)}`);
- }
- console.log(`Purchased decoration is ${countBaloons} balloons, ${countRibbon} m ribbon, ${countFlowers} flowers and ${countCandles} candles.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment