Advertisement
GalinaKG

Untitled

Apr 29th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. function easterDecoration (input) {
  2. let index = 0;
  3. let clients = Number(input[index]);
  4. index++;
  5. let sum = 0;
  6.  
  7. for (let i = 1; i <= clients; i++) {
  8. let command = input[index];
  9. let price = 0;
  10. let countPurches = 0;
  11.  
  12. while (command !== "Finish") {
  13. let purchase = input[index];
  14.  
  15. switch (purchase) {
  16. case "basket":
  17. price += 1.50;
  18. countPurches++
  19. break;
  20. case "wreath":
  21. price += 3.80;
  22. countPurches++;
  23. break;
  24. case "chocolate bunny":
  25. price += 7;
  26. countPurches++
  27. break;
  28. }
  29.  
  30.  
  31. command = input[index];
  32. index++;
  33. }
  34.  
  35. if (command === "Finish") {
  36. if (countPurches % 2 !== 0) {
  37. sum += price;
  38. console.log(`You purchased ${countPurches} items for ${price.toFixed(2)} leva.`);
  39. } else {
  40. price -= (price * 0.20);
  41. sum += price;
  42. console.log(`You purchased ${countPurches} items for ${price.toFixed(2)} leva.`);
  43. }
  44. }
  45.  
  46. }
  47. let avg = sum / clients;
  48. console.log(`Average bill per client is: ${avg.toFixed(2)} leva.`);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement