Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(journeyCost, months) {
  2.   let saveMoneySum = 0;
  3.   let monthCounter = 0;
  4.   let monthSaveMoney = journeyCost * 0.25;
  5.   let monthBonus = 0;
  6.   let spentMoney = 0;
  7.  
  8.   for (let i = 1; i <= months; i++) {
  9.     monthCounter++;
  10.     if (i % 2 !== 0 && i !== 1) {
  11.       spentMoney = saveMoneySum * 0.16;
  12.       saveMoneySum -= spentMoney;
  13.     }
  14.     if (monthCounter === 4) {
  15.       monthBonus = saveMoneySum * 0.25;
  16.       saveMoneySum += monthBonus;
  17.       monthCounter = 0;
  18.     }
  19.     saveMoneySum += monthSaveMoney;
  20.   }
  21.   if (saveMoneySum >= journeyCost) {
  22.     console.log(
  23.       `Bravo! You can go to Disneyland and you will have ${(
  24.         saveMoneySum - journeyCost
  25.       ).toFixed(2)}lv. for souvenirs.`
  26.     );
  27.   } else {
  28.     console.log(
  29.       `Sorry. You need ${(journeyCost - saveMoneySum).toFixed(2)}lv. more.`
  30.     );
  31.   }
  32. }
  33.  
  34. solve(3265, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement