Advertisement
desislava_topuzakova

02

Aug 20th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. function solve(input){
  2. let beerPrice = 1.20
  3. let nameOfFan = input[0]
  4. let wallet = Number(input[1])
  5. let beerCount = Number(input[2])
  6. let chipsCount = Number(input[3])
  7.  
  8. let totalBeerCost = beerCount * beerPrice
  9. let priceChips = 0.45 * totalBeerCost
  10. let totalChipsCost =(Math.ceil(chipsCount * priceChips))
  11. let total = totalBeerCost + totalChipsCost
  12.  
  13. if (total <=wallet){
  14. total = (Math.abs(total - wallet).toFixed(2))
  15. console.log(`${nameOfFan} bought a snack and has ${(total)} leva left.`);
  16. }else {
  17. total =(Math.abs(total - wallet).toFixed(2))
  18. console.log(`${nameOfFan} needs ${total} more leva!`)
  19. }
  20.  
  21.  
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement