Advertisement
DraconiusNX

Untitled

Sep 18th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pcShopping(data) {
  2.     var totalBudget = Number(data[0]);
  3.     var gpuCount = Number(data[1]);
  4.     var cpuCount = Number(data[2]);
  5.     var ramCount = Number(data[3]);
  6.     var gpuPrice = 250;
  7.     var gpuTotal = gpuCount * gpuPrice;
  8.     var cpuPrice = gpuTotal / 100 * 35;
  9.     var ramPrice = gpuTotal / 100 * 10;
  10.     var totalMoney = gpuTotal + cpuCount * cpuPrice + ramCount * ramPrice;
  11.     if (gpuCount > cpuCount) {
  12.         totalMoney = totalMoney - (totalMoney * 15 / 100);
  13.     }
  14.     if (totalMoney > totalBudget) {
  15.         var moneyNeeded = totalMoney - totalBudget;
  16.         console.log(`Not enough money! You need ${moneyNeeded.toFixed(2)} leva more!`)
  17.     } else {
  18.         var moneyExtra = totalBudget - totalMoney;
  19.         console.log(`You have ${moneyExtra.toFixed(2)} leva left!`)
  20.     }
  21. }
  22.  
  23. pcShopping(['900', '2', '1', '3']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement