Advertisement
cecko

Untitled

Oct 17th, 2022
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function shopping(input) {
  2. let peturBuget = Number(input[0]);
  3. let videoCards = Number(input[1]);
  4. let processors = Number(input[2]);
  5. let ram = Number(input[3]);
  6.  
  7. // let videoCardSum = videoCards * 250;
  8. // let processorPrice = videoCardSum * 0.35;
  9.  
  10. // let processorSum = processors * processorPrice;
  11. // let ramPrice = videoCardSum * 0.10;
  12. // let ramSum = ramPrice * ram;
  13. let videoCardSum = videoCards * 250;
  14. let processorPrice = (videoCardSum * 0.35) * processors;
  15. let ramPrice = (videoCardSum * 0.1) * ram;
  16. let totalPrice = videoCardSum + processorPrice + ramPrice
  17.  
  18. let totalSum = videoCardSum + processorPrice + ramPrice;
  19.  
  20. if (videoCards > processors) {
  21. totalSum = totalSum * 0.85;
  22. }
  23. let diff = Math.abs(peturBuget - totalSum);
  24.  
  25.  
  26. if (totalSum <= peturBuget){
  27. console.log(`You have ${diff.toFixed(2)} leva left!`);
  28. } else {
  29. console.log(`Not enough money! You need ${diff.toFixed(2)} leva more!`)
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement