Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cleverLily(input) {
- let age = Number(input[0]);
- let washingMachinePrice = Number(input[1]);
- let singleToyPrice = Number(input[2]);
- let toysCounter = 0;
- let savedMoney = 0;
- let stolenMoney = 0;
- let addedMoney = 10;
- for (let index = 1; index <= age; index++) {
- if (index % 2 === 0) {
- savedMoney += addedMoney;
- stolenMoney++;
- addedMoney += 10;
- } else {
- toysCounter++;
- }
- }
- let sum = toysCounter * singleToyPrice;
- let totalMoney = (savedMoney + sum) - stolenMoney;
- if (totalMoney >= washingMachinePrice) {
- console.log(`Yes! ${(totalMoney - washingMachinePrice).toFixed(2)}`);
- } else {
- console.log(`No! ${(washingMachinePrice - totalMoney).toFixed(2)}`);
- }
- }
- cleverLily(["10", "170.00", "6"])
Advertisement
Add Comment
Please, Sign In to add comment