Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function easterDecoration(input) {
- let buyers = Number(input[0]);
- let index = 1;
- let totalPrice = 0;
- for (let i = 0; i < buyers; i++){
- let command = input[index];
- index++;
- let price = 0;
- let boughtItems = 0;
- while (command !== "Finish") {
- let purchase = command;
- boughtItems++;
- if (purchase === "basket") {
- price += 1.50;
- } else if ( purchase === "wreath") {
- price += 3.80;
- } else if (purchase === "chocolate bunny") {
- price += 7;
- }
- command = input[index];
- index++;
- }
- if (boughtItems % 2 === 0) {
- price *= 0.80;
- }
- totalPrice += price;
- console.log(`You purchased ${boughtItems} items for ${price.toFixed(2)} leva.`);
- }
- console.log(`Average bill per client is: ${(totalPrice / buyers).toFixed(2)} leva.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment