Advertisement
Didart

Shopping

Mar 7th, 2022
1,228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function shopping(input) {
  2.     let budget = Number(input[0]);
  3.     let GPU = Number(input[1]);
  4.     let CPU = Number(input[2]);
  5.     let RAM = Number(input[3]);
  6.  
  7.     let moneyForGPU = GPU * 250;
  8.     let moneyForCPU = (moneyForGPU * 0.35) * CPU;
  9.     let moneyForRAM = (moneyForGPU * 0.1) * RAM;
  10.  
  11.     let totalSum = moneyForGPU + moneyForCPU + moneyForRAM;
  12.  
  13.     if (GPU > CPU) {
  14.         totalSum = totalSum * 0.85;
  15.     }
  16.    
  17.     if (totalSum <= budget) {
  18.         console.log(`You have ${(budget - totalSum).toFixed(2)} leva left!`);
  19.     } else {
  20.         console.log(`Not enough money! You need ${(totalSum - budget).toFixed(2)} leva more!`);
  21.     }
  22. }
  23.  
  24. shopping(["900", "2", "1", "3"])
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement