TZinovieva

Easter Decoration

Dec 28th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function easterDecoration(input) {
  2.     let buyers = Number(input[0]);
  3.     let index = 1;
  4.  
  5.     let totalPrice = 0;
  6.     for (let i = 0; i < buyers; i++){
  7.         let command = input[index];
  8.         index++;
  9.  
  10.         let price = 0;
  11.         let boughtItems = 0;
  12.         while (command !== "Finish") {
  13.             let purchase = command;
  14.             boughtItems++;
  15.            
  16.             if (purchase === "basket") {
  17.                 price += 1.50;
  18.             } else if ( purchase === "wreath") {
  19.                 price += 3.80;
  20.             } else if (purchase === "chocolate bunny") {
  21.                 price += 7;
  22.             }
  23.             command = input[index];
  24.             index++;
  25.         }
  26.             if (boughtItems % 2 === 0) {
  27.             price *= 0.80;
  28.             }
  29.         totalPrice += price;
  30.         console.log(`You purchased ${boughtItems} items for ${price.toFixed(2)} leva.`);
  31.     }
  32.     console.log(`Average bill per client is: ${(totalPrice / buyers).toFixed(2)} leva.`);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment