Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function backToThePast(input) {
- let inheritedMoney = Number(input[0]);
- let lastYear = Number(input[1]);
- let age = 18;
- let spentMoney = 0;
- for (let i = 1800; i <= lastYear; i++) {
- let currentAge = age++;
- if (i % 2 === 0) {
- spentMoney += 12000;
- } else {
- spentMoney += 12000 + 50 * currentAge;
- }
- }
- if (inheritedMoney >= spentMoney) {
- console.log(`Yes! He will live a carefree life and will have ${(inheritedMoney - spentMoney).toFixed(2)} dollars left.`);
- } else {
- console.log(`He will need ${(spentMoney - inheritedMoney).toFixed(2)} dollars to survive.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment