Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. function args(input){
  2. let numberOfDays = Number(input.shift());
  3. let dailyLimit = 60;
  4.  
  5. for(let i = 1; i <= numberOfDays; i++){
  6. let moneySpent = 0;
  7. let productCount = 0;
  8. while(dailyLimit - moneySpent !== 0){
  9. let productPrice = input.shift();
  10. if(productPrice === "Day over"){
  11. let moneyLeft = dailyLimit - moneySpent;
  12. console.log(`Money left from today: ${moneyLeft.toFixed(2)}. You've bought ${productCount} products.`);
  13. dailyLimit += moneyLeft;
  14. break;
  15. }
  16. if(dailyLimit - moneySpent < Number(productPrice)){
  17. continue;
  18. }
  19. moneySpent += Number(productPrice);
  20. productCount++;
  21. if(dailyLimit - moneySpent === 0){
  22. dailyLimit = 60;
  23. console.log( `Daily limit exceeded! You've bought ${productCount} products.`)
  24. break;
  25. }
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement