TZinovieva

Clever Lily

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