Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function result(age, priceMachine, priceToy) {
- age = Number(age);
- priceMachine = Number(priceMachine);
- priceToy = Number(priceToy);
- let money = 0;
- let birthdayMoney = 10;
- let toys = 0;
- for (let i = 1; i <= age; i++) {
- if (i % 2 == 0) {
- money += birthdayMoney;
- birthdayMoney += 10;
- money -= 1;
- } else {
- toys++;
- }
- }
- money += toys * priceToy;
- if (money >= priceMachine) {
- console.log(`Yes! ${(money - priceMachine).toFixed(2)}`);
- } else {
- console.log(`No! ${(priceMachine - money).toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment