Advertisement
Guest User

Untitled

a guest
Jun 30th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function disneylandJourney(price,months) {
  2.     //you need 1000 leva for the journey and you have 4 months to collect them
  3.     //on the 2nd line you will receive the number of months for which you have to collect money –
  4.     //an integer number in the range [1…12]:
  5.  
  6.     saveMoney=0;
  7.    
  8.     for (let i = 1; i < months; i++) {
  9.         let forFirstMonth = price * 0.25; //Every month you can save 1000 * 25% => 250lv
  10.         if (months >= 2) {
  11.            let  SecondMonth = forFirstMonth + 250; //To the end of the 2nd month -  250 + 250 => 500 lv
  12.             //To the begging of the 3th month (odd month) you spent 80 lv. (500 * 16%) for clothes
  13.             //and shoes, then you save 250 lv, so now you have 670 lv:
  14.             if (months % 2 !== 0) {
  15.                 let ForThird = SecondMonth * 0.16;
  16.                 if (months === 4) {
  17.                     savedMoney = forFirstMonth + savedMoney + secondMonth + forThird
  18.                     forFourMonth = savedMoney + (savedMoney * 0.25) + 25; //Last month is the fourth month and you save
  19.                     //670 + 167.5(670 * 25%) + 25 = 1087.5 lv
  20.                 }
  21.                 //You have 1087.5 – 1000 = 87.5 lv., so you can go to the trip:
  22.                 //console.log(savedMoney - journeyPrice);
  23.             }
  24.         }
  25.     }
  26.     if (price >= forFourMonth) {
  27.         console.log(`Bravo! You can go to Disneyland and you will have ${forFourMonth.toFixed(2)}lv. for souvenirs.`);
  28.     } else {
  29.         console.log(`Sorry. You need ${(forFourMonth - price).toFixed(2)}lv. more.`);
  30.     }
  31. }
  32. disneylandJourney(1000, 4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement