Advertisement
Liliana797979

vqrno reshenie na shopping

Dec 22nd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function shopping(budget, videoCardCount, processorsCount, ramMemoryCount) {
  2.     arguments = [...arguments].map(arg => +arg);
  3.     const calcDiscountedPricePerItem = (price, percentage) => price - price * (1 - percentage);
  4.  
  5.     const gpuPrice = 250;
  6.     const cpuPricePercentage = 0.35;
  7.     const ramPricePercentage = 0.1;
  8.     const gpuPercentageDiscount = 0.15;
  9.  
  10.     const totalGpuPrice = videoCardCount * gpuPrice;
  11.     const totalCpuPrice = processorsCount * calcDiscountedPricePerItem(totalGpuPrice, cpuPricePercentage);
  12.     const totalRamPrice = ramMemoryCount * calcDiscountedPricePerItem(totalGpuPrice, ramPricePercentage);
  13.  
  14.     let totalSum = totalGpuPrice + totalCpuPrice + totalRamPrice;
  15.  
  16.     if (videoCardCount > processorsCount) {
  17.         totalSum *= 1 - gpuPercentageDiscount;
  18.     }
  19.  
  20.     const cost = budget - totalSum;
  21.  
  22.     if (cost >= 0) {
  23.         console.log(`You have ${cost.toFixed(2)} leva left!`);
  24.     } else {
  25.         console.log(`Not enough money! You need ${(-cost).toFixed(2)} leva more!`);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement