TZinovieva

Back To The Past 100/100

Oct 3rd, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function backToThePast(input) {
  2.     let inheritedMoney = Number(input[0]);
  3.     let lastYear = Number(input[1]);
  4.     let age = 18;
  5.  
  6.     let spentMoney = 0;
  7.     for (let i = 1800; i <= lastYear; i++) {
  8.         let currentAge = age++;
  9.         if (i % 2 === 0) {
  10.             spentMoney += 12000;
  11.         } else {
  12.             spentMoney += 12000 + 50 * currentAge;
  13.         }
  14.     }
  15.     if (inheritedMoney >= spentMoney) {
  16.         console.log(`Yes! He will live a carefree life and will have ${(inheritedMoney - spentMoney).toFixed(2)} dollars left.`);
  17.     } else {
  18.         console.log(`He will need ${(spentMoney - inheritedMoney).toFixed(2)} dollars to survive.`);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment