Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cleverLili(input) {
- let age = Number(input[0]);
- let washingMachinePrice = Number(input[1]);
- let toyPrice = Number(input[2]);
- let sumOfToys = 0;
- let sumOfMoney = 0;
- let currentMoney = 0;
- for (let i = 1; i <= age; i++) {
- if (i % 2 === 0) {
- sumOfMoney += currentMoney;
- currentMoney += 10;
- sumOfMoney -= 1;
- } else {
- sumOfToys++;
- }
- sumOfMoney += sumOfToys * toyPrice;
- }
- if (sumOfMoney >= washingMachinePrice) {
- console.log(`Yes! ${(sumOfMoney - washingMachinePrice).toFixed(2)}`);
- } else {
- console.log(`No! ${(washingMachinePrice - sumOfMoney).toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement