Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(age, priceWashing, priceToy) {
  2.  
  3.     age = Number(age);
  4.     priceWashing = Number(priceWashing);
  5.     priceToy = Number(priceToy);
  6.  
  7.     let money = 10;
  8.     let toys = 0;
  9.     let saveMoney = 0
  10.  
  11.     for (let i = 1; i <= age; i++) {
  12.         if (i % 2 == 0) {
  13.             saveMoney += money -1;
  14.             money+=10
  15.  
  16.  
  17.  
  18.         } else {
  19.             toys++
  20.  
  21.  
  22.         }
  23.  
  24.     } let moneyForToys = priceToy * toys;
  25.     saveMoney += moneyForToys;
  26.     if (saveMoney >= priceWashing) {
  27.         console.log(`Yes! ${(saveMoney - priceWashing).toFixed(2)}`);
  28.  
  29.     } else {
  30.         console.log(`No! ${(priceWashing - saveMoney).toFixed(2)}`);
  31.  
  32.  
  33.     }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement