Advertisement
ExGiX

Untitled

Mar 27th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. function tripExpenses(input) {
  2.  
  3. let vacationDays = Number(input.shift());
  4.  
  5. for(let i = 0; i < vacationDays; i++) {
  6. let limit = 60;
  7. let productCount = 0;
  8. let command = input.shift();
  9. let totalPriceForDay = 0;
  10. let moneyLeft = 0;
  11.  
  12.  
  13.  
  14. while(command !== 'Day over') {
  15.  
  16. let priceOfProduct = Number(command);
  17. totalPriceForDay += priceOfProduct;
  18. productCount++;
  19.  
  20. if(totalPriceForDay >= 60) {
  21.  
  22. console.log(`Daily limit exceeded! You've bought ${productCount} products.`)
  23. break;
  24. }
  25.  
  26.  
  27. command = input.shift();
  28.  
  29. }
  30.  
  31. if(totalPriceForDay < 60) {
  32.  
  33. moneyLeft = limit - totalPriceForDay;
  34.  
  35. console.log(`Money left from today: ${moneyLeft.toFixed(2)}. You've bought ${productCount} products.`)
  36.  
  37.  
  38.  
  39.  
  40. }
  41.  
  42.  
  43.  
  44.  
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement