vikkktor

backToThePast

Jun 8th, 2021 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function backToThePast(input) {
  2.  
  3.     let money = Number(input[0]);
  4.     let lifeCycle = Number(input[1]);
  5.     let age = 18;
  6.  
  7.     for (i = 1800; i <= lifeCycle; i++) {
  8.         if (i % 2 === 0) {
  9.             money = money - 12000;
  10.             age++;
  11.         } else {
  12.             money = money - (12000 + 50 * age);
  13.             age++;
  14.         }
  15.     }
  16.  
  17.     if (money >= 0) {
  18.         console.log(`Yes! He will live a carefree life and will have ${money.toFixed(2)} dollars left.`);
  19.     }
  20.     else {
  21.         console.log(`He will need ${Math.abs(money).toFixed(2)} dollars to survive.`);
  22.     }
  23. }
  24. backToThePast([100000.15, 1808])
Add Comment
Please, Sign In to add comment