Advertisement
PowerCell46

Smart Lilly JS

Sep 29th, 2022 (edited)
1,132
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cleverLilly(input) {
  2.    
  3.     let age = Number(input[0]);
  4.     let priceOfTheWashingMachine = Number(input[1]);
  5.     let priceForOneToy = Number(input[2]);
  6.     let money = 0;
  7.     let numberofBirthdaysForToys = 0;
  8.     let numberofBirthdaysForMoney = 0;
  9.     let currentMoney = 10;
  10.  
  11.     for(let rotatingAge = 1; rotatingAge <= age; rotatingAge++) {
  12.         if(rotatingAge % 2 === 0) {
  13.     numberofBirthdaysForMoney++;
  14.     money += currentMoney;
  15.     currentMoney += 10;
  16.     } else {
  17.     numberofBirthdaysForToys++;
  18.     }
  19.     }
  20.     let moneyFromMoney = money - (numberofBirthdaysForMoney * 1);
  21.     let moneyFromToys = numberofBirthdaysForToys * priceForOneToy;
  22.  
  23.     let sumOfMoney = moneyFromMoney + moneyFromToys;
  24.    
  25.     if(sumOfMoney >= priceOfTheWashingMachine) {
  26.         let leftMoney = sumOfMoney - priceOfTheWashingMachine;
  27.         console.log("Yes! " + leftMoney.toFixed(2));
  28.     } else if(priceOfTheWashingMachine > sumOfMoney) {
  29.         let notEnoughMoney = priceOfTheWashingMachine - sumOfMoney;
  30.         console.log("No! " + notEnoughMoney.toFixed(2));
  31.     }
  32. }
Advertisement
Comments
  • mohandsedu
    66 days
    # text 0.15 KB | 0 0
    1. {
    2. "discord_token" : "645365862433423382",
    3. "shards": {
    4. "count": 1,
    5. "first_shard_id": 0,
    6. "last_shard_id": 0
    7. }
    8. }
Add Comment
Please, Sign In to add comment
Advertisement