ExGiX

Untitled

Mar 27th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. function touristshop(input) {
  2. let budget = Number(input.shift());
  3. //let budgetTmp = budget
  4. let price = 0;
  5. let command = input.shift();
  6. let counter = 0;
  7.  
  8. while (command != "Stop") {
  9. counter++;
  10. if (counter % 3 == 0) {
  11. price += Number(input.shift())/2
  12.  
  13. } else {
  14. price += Number(input.shift())
  15. }
  16. if (price > budget) {
  17. console.log(You don't have enough money!);
  18. console.log(You need ${Math.abs(price - budget).toFixed(2)} leva!);
  19. return
  20. } //else {
  21.  
  22. /* budgetTmp -= price;
  23. //result += price;
  24. if (budgetTmp == 0) {
  25. break;
  26. } */
  27. //}
  28.  
  29. command = input.shift()
  30.  
  31. }
  32. console.log(You bought ${counter} products for ${price.toFixed(2)} leva.);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment