Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cleverLilly(input) {
- let age = Number(input[0]);
- let washPrice = Number(input[1]);
- let priceForToy = Number(input[2]);
- let toys = 0;
- let money = 0;
- let counter = 1;
- let spendMoney = 0;
- let moneyForBrother = 0;
- for (let i = 1; i <= age; i++) {
- if (i % 2 == 0) {
- spendMoney += 10 + money;
- moneyForBrother += 1;
- if (counter % 2 == 0) {
- money += 10;
- }
- } else {
- toys += 1;
- }
- counter += 1;
- }
- let moneyForToys = toys * priceForToy;
- let totalSum = spendMoney + moneyForToys - moneyForBrother;
- let diff = Math.abs(totalSum - washPrice);
- if (totalSum >= washPrice) {
- console.log(`Yes! ${diff.toFixed(2)}`);
- } else {
- console.log(`No! ${diff.toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment