didkoslawow

Untitled

Sep 21st, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. function shopping(input) {
  2.  
  3. let budget = Number(input[0]);
  4. let vgas = Number(input[1]);
  5. let cpus = Number(input[2]);
  6. let rams = Number(input[3]);
  7.  
  8. let vgaPrice = 250;
  9. let cpuPrice = vgas * vgaPrice * 0.35;
  10. let ramPrice = vgas * vgaPrice * 0.10;
  11.  
  12. let totalPrice = vgas * vgaPrice + cpus * cpuPrice + rams * ramPrice;
  13.  
  14. if (vgas > cpus) {
  15. totalPrice = totalPrice - totalPrice * 0.15;
  16. }
  17.  
  18. let money = Math.abs(budget - totalPrice);
  19.  
  20. if (budget >= money) {
  21. console.log(`You have ${money.toFixed(2)} leva left!`);
  22. } else {
  23. console.log(`Not enough money! You need ${money.toFixed(2)} leva more!`);
  24. }
  25.  
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment