Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (ageInput, loundryPriceInput, toyPriceInput) {
  2.     let age = Number (ageInput);
  3.     let loundryPrice = Number (loundryPriceInput);
  4.     let toyPrice = Number (toyPriceInput);
  5.  
  6.     let moneySaved = 0;
  7.     let moneyGift = 0;
  8.     let toyCnt = 0;
  9.  
  10.      for (i = 0; i <= age; i ++) {
  11.          if (i % 2 != 0) {
  12.              toyCnt ++;
  13.          } else if ((i % 2 == 0) && (i != 0)) {
  14.              moneyGift += 10;
  15.              moneySaved = moneySaved + moneyGift - 1;
  16.          }
  17.      }
  18.      
  19.      let totalToyPrice = toyCnt * toyPrice;
  20.      let totalMoneyGathered = moneySaved + totalToyPrice;
  21.      let difference = Math.abs (totalMoneyGathered - loundryPrice);
  22.  
  23.      if (totalMoneyGathered >= loundryPrice) {
  24.          console.log (`Yes! ${difference.toFixed(2)}`);
  25.      } else {
  26.          console.log (`No! ${difference.toFixed(2)}`)
  27.      }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement