Advertisement
dimoBs

Untitled

Oct 6th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. function solve(index) {
  2. let moneyFortune = Number(index.shift());
  3. let yearLive = Number(index.shift());
  4. let yearBack = 1800;
  5. let spendEvYear = 12000;
  6. let countEven = 0;
  7. let countOdd = 0;
  8.  
  9. for (let i = yearLive; i >= yearBack; i--) {
  10. if (i % 2 === 0) {
  11. countEven++;
  12. } else {
  13. countOdd++;
  14. }
  15. }
  16. let curnetYears = yearLive - yearBack + 18 - countOdd;
  17. let spendOddYear = (12000 + (50 * curnetYears));
  18. let spendA = (moneyFortune - ((countEven * spendEvYear) + (countOdd * spendOddYear)));
  19. let spend = Math.abs(spendA);
  20. if (spendA >= 0) {
  21. console.log(`Yes! He will live a carefree life and will have ${spend.toFixed(2)} dollars left.`);
  22. } else {
  23. console.log(`He will need ${spend.toFixed(2)} dollars to survive.`);
  24. }
  25.  
  26.  
  27. }
  28. //solve(50000, 1802);
  29. solve(["100000.15", "1808"]);
  30. //solve("50000",
  31. //"1802");
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement