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 toyPrice = Number(input[2]);
- let evenSum = 0;
- let totalEvenSum = 0;
- let brotherMoney = 0;
- let toys = 0;
- for (let i = 1; i <= age; i++){
- if (i % 2 === 0){
- evenSum += 10;
- totalEvenSum += evenSum;
- brotherMoney += 1;
- } else {
- toys ++;
- }
- }
- let totalBirthdaySum = totalEvenSum + toys * toyPrice - brotherMoney;
- if (totalBirthdaySum >= washingMachinePrice){
- console.log(`Yes! ${(totalBirthdaySum - washingMachinePrice).toFixed(2)}`);
- } else {
- console.log(`No! ${(washingMachinePrice - totalBirthdaySum).toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment