Didart

Clever Lily

Apr 9th, 2022
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cleverLily(input) {
  2.    
  3.     let age = Number(input[0]);
  4.     let washingMachinePrice = Number(input[1]);
  5.     let singleToyPrice = Number(input[2]);
  6.  
  7.     let toysCounter = 0;
  8.     let savedMoney = 0;
  9.     let stolenMoney = 0;
  10.     let addedMoney = 10;
  11.  
  12.     for (let index = 1; index <= age; index++) {
  13.  
  14.         if (index % 2 === 0) {
  15.             savedMoney += addedMoney;
  16.             stolenMoney++;
  17.             addedMoney += 10;
  18.         } else {
  19.             toysCounter++;
  20.         }
  21.     }
  22.     let sum = toysCounter * singleToyPrice;
  23.     let totalMoney = (savedMoney + sum) - stolenMoney;
  24.  
  25.     if (totalMoney >= washingMachinePrice) {
  26.         console.log(`Yes! ${(totalMoney - washingMachinePrice).toFixed(2)}`);
  27.     } else {
  28.         console.log(`No! ${(washingMachinePrice - totalMoney).toFixed(2)}`);
  29.     }
  30.  
  31. }
  32.  
  33. cleverLily(["10", "170.00", "6"])
  34.  
Advertisement
Add Comment
Please, Sign In to add comment