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