ProdanTenev

Clever Lilly

Mar 1st, 2022
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.87 KB | None | 0 0
  1. function cleverLilly(input) {
  2.     let age = Number(input[0]);
  3.     let washPrice = Number(input[1]);
  4.     let priceForToy = Number(input[2]);
  5.     let toys = 0;
  6.     let money = 0;
  7.     let counter = 1;
  8.     let spendMoney = 0;
  9.     let moneyForBrother = 0;
  10.     for (let i = 1; i <= age; i++) {
  11.          if (i % 2 == 0) {
  12.              spendMoney += 10 + money;
  13.              moneyForBrother += 1;
  14.              if (counter % 2 == 0) {
  15.                  money += 10;
  16.              }
  17.          } else {
  18.              toys += 1;
  19.          }
  20.          counter += 1;
  21.     }
  22.     let moneyForToys = toys * priceForToy;
  23.     let totalSum = spendMoney  + moneyForToys - moneyForBrother;
  24.     let diff = Math.abs(totalSum - washPrice);
  25.     if (totalSum >= washPrice) {
  26.         console.log(`Yes! ${diff.toFixed(2)}`);
  27.     } else {
  28.         console.log(`No! ${diff.toFixed(2)}`);
  29.        
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment