Spocoman

04. Toy Shop

Dec 16th, 2021 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function toyShop(input) {
  2.    
  3.     let amount = parseFloat(input[0]);
  4.     let puzzles = parseInt(input[1]);
  5.     let dolls = parseInt(input[2]);
  6.     let bears = parseInt(input[3]);
  7.     let minions = parseInt(input[4]);
  8.     let trucks = parseInt(input[5]);
  9.  
  10.     let puzzlesPrice = puzzles * 2.6;
  11.     let dollsPrice =  dolls * 3;
  12.     let bearsPrice = bears * 4.1;
  13.     let minionsPrice = minions * 8.2;
  14.     let trucksPrice =  trucks * 2;
  15.     let toys = puzzles + dolls + bears + minions + trucks;
  16.     let price = puzzlesPrice + dollsPrice + bearsPrice + minionsPrice + trucksPrice;
  17.            
  18.     if (toys >= 50){
  19.       price *= 0.75;
  20.     }
  21.  
  22.     price *= 0.9;
  23.  
  24.     if (price >= amount){
  25.       console.log(`Yes! ${(price - amount).toFixed(2)} lv left.`);
  26.     }else{
  27.       console.log(`Not enough money! ${(amount - price).toFixed(2)} lv needed.`);
  28.     }
  29.  
  30. }
  31.  
Add Comment
Please, Sign In to add comment