desito07

Back To The Past

Apr 10th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. function backToThePast(input) {
  2. let moneyGiven = Number(input.shift());
  3. let year = Number(input.shift());
  4.  
  5. let age = 18;
  6. let moneySpend = 0;
  7.  
  8. for (let i = 1800; i <= year; i++) {
  9. if (i % 2 === 0) {
  10. moneySpend += 12000;
  11. } else {
  12. moneySpend += 12000 + 50 * age;
  13. }
  14. age++;
  15. }
  16. if (moneyGiven >= moneySpend) {
  17. console.log(
  18. `Yes! He will live a carefree life and will have ${(
  19. moneyGiven - moneySpend
  20. ).toFixed(2)} dollars left.`
  21. );
  22. } else {
  23. console.log(
  24. `He will need ${Math.abs(moneyGiven - moneySpend).toFixed(
  25. 2
  26. )} dollars to survive.`
  27. );
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment