Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. function trip(input) {
  2.  
  3. let moneyToTrip = Number(input[0]);
  4. let months = Number(input[1]);
  5. let totalSum = 0;
  6. let savedMoneyPerMonth = moneyToTrip * 0.25;
  7.  
  8. for (let i = 1; i <= months; i++) {
  9.  
  10. if(i % 2 !== 0 && i !== 1) {
  11. let spendMoney = totalSum - (totalSum * 0.84);
  12. totalSum -= spendMoney;
  13. }
  14. if (i % 4 === 0) {
  15. let bossBonus = totalSum * 0.25;
  16. totalSum += bossBonus;
  17. }
  18.  
  19. totalSum += savedMoneyPerMonth;
  20. }
  21.  
  22. if (totalSum >= moneyToTrip) {
  23. let leftMoney = totalSum - moneyToTrip;
  24. console.log(`Bravo! You can go to Disneyland and you will have ${leftMoney.toFixed(2)}lv. for souvenirs.`);
  25. } else {
  26. let neededMoney = moneyToTrip - totalSum;
  27. console.log(`Sorry. You need ${neededMoney.toFixed(2)}lv. more.`);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement