Advertisement
Guest User

Untitled

a guest
Jun 17th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. function touristShop(input) {
  2. let budget = Number(input[0]);
  3.  
  4. let index = 1;
  5. let command = input[index++];
  6. let productsCount = 0;
  7. let totalPrice = 0;
  8. let notEnought = false;
  9. let daysCount = 1;
  10.  
  11. while (command !== "Stop") {
  12. let productName = command;
  13. let priceProduct = Number(input[index++]);
  14.  
  15. if (daysCount % 3 === 0) {
  16. priceProduct /= 2;
  17. }
  18.  
  19. if (priceProduct > budget) {
  20. notEnought = true;
  21. console.log(`You don't have enough money!`);
  22. console.log(`You need ${priceProduct - budget} leva!`);
  23. break;
  24. }
  25.  
  26. budget -= priceProduct;
  27. totalPrice += priceProduct;
  28.  
  29.  
  30. productsCount++;
  31. daysCount++;
  32. command = input[index++]
  33. }
  34.  
  35. if (!notEnought) {
  36. console.log(`You bought ${productsCount} products for ${totalPrice} leva.`)
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement