Advertisement
Liliana797979

clever lili

Feb 12th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cleverLili(input) {
  2.     let age = Number(input[0]);
  3.     let washingMachinePrice = Number(input[1]);
  4.     let toyPrice = Number(input[2]);
  5.  
  6.     let sumOfToys = 0;
  7.     let sumOfMoney = 0;
  8.     let currentMoney = 0;
  9.  
  10.     for (let i = 1; i <= age; i++) {
  11.         if (i % 2 === 0) {
  12.             sumOfMoney += currentMoney;
  13.             currentMoney += 10;
  14.             sumOfMoney -= 1;
  15.         } else {
  16.             sumOfToys++;
  17.         }
  18.         sumOfMoney += sumOfToys * toyPrice;
  19.     }
  20.     if (sumOfMoney >= washingMachinePrice) {
  21.         console.log(`Yes! ${(sumOfMoney - washingMachinePrice).toFixed(2)}`);
  22.     } else {
  23.         console.log(`No! ${(washingMachinePrice - sumOfMoney).toFixed(2)}`);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement