Advertisement
dimoBs

01. Back To The Past

Sep 26th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(moneyFortune, yearLive) {
  2.     moneyFortune = Number(moneyFortune);
  3.     yearLive = Number(yearLive);
  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.toFixed(2));
  20.     if (spendA >= 0) {
  21.         console.log(`Yes! He will live a carefree life and will have ${spend} dollars left.`);
  22.     } else {
  23.         console.log(`He will need ${spend} dollars to survive.`);
  24.     }
  25.  
  26.  
  27. }
  28. //solve(50000, 1802);
  29. solve(100000.15,1808);
  30.  
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement