Neri0817

Back To The Past \\ PB More Exersise

Apr 16th, 2021 (edited)
69
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function backToThePast(input) {
  2.     let i = 0;
  3.     let money = Number(input[i++]);
  4.     let year = Number(input[i++]);
  5.     let age = 17;
  6.  
  7.     for (let j = 1800; j <= year; j++) {
  8.         if (j % 2 === 0) {
  9.             age++;
  10.             money -= 12000;
  11.         } else {
  12.             age++;
  13.             money -= 12000 + age * 50;
  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.     } else {
  20.         console.log(`He will need ${Math.abs(money).toFixed(2)} dollars to survive.`);
  21.     }
  22. }
RAW Paste Data