dninov81

Untitled

May 16th, 2020
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function result(age, priceMachine, priceToy) {
  2.   age = Number(age);
  3.   priceMachine = Number(priceMachine);
  4.   priceToy = Number(priceToy);
  5.  
  6.   let money = 0;
  7.   let birthdayMoney = 10;
  8.   let toys = 0;
  9.  
  10.   for (let i = 1; i <= age; i++) {
  11.     if (i % 2 == 0) {
  12.       money += birthdayMoney;
  13.       birthdayMoney += 10;
  14.       money -= 1;
  15.     } else {
  16.       toys++;
  17.     }
  18.   }
  19.  
  20.   money += toys * priceToy;
  21.  
  22.   if (money >= priceMachine) {
  23.     console.log(`Yes! ${(money - priceMachine).toFixed(2)}`);
  24.   } else {
  25.     console.log(`No! ${(priceMachine - money).toFixed(2)}`);
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment