Advertisement
Spocoman

01. Back To The Past

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