Advertisement
Spocoman

Easter Decoration

Feb 15th, 2022
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function easterDecoration(input) {
  2.     let clients = Number(input.shift());
  3.     let total = 0;
  4.  
  5.     for (let i = 0; i < clients; i++) {
  6.         let stock = input.shift();
  7.         let counter = 0;
  8.         let sum = 0;
  9.  
  10.         while (stock !== "Finish") {
  11.             switch (stock) {
  12.                 case "basket":
  13.                     sum += 1.5;
  14.                     break;
  15.  
  16.                 case "wreath":
  17.                     sum += 3.8;
  18.                     break;
  19.  
  20.                 case "chocolate bunny":
  21.                     sum += 7;
  22.                     break;
  23.             }
  24.             stock = input.shift();
  25.             counter++;
  26.         }
  27.  
  28.         if (counter % 2 === 0) {
  29.             sum *= 0.8;
  30.         }
  31.  
  32.         total += sum;
  33.         console.log(`You purchased ${counter} items for ${sum.toFixed(2)} leva.`);
  34.     }
  35.     console.log(`Average bill per client is: ${(total / clients).toFixed(2)} leva.`);
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement