Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function shopping(budget, videoCardCount, processorsCount, ramMemoryCount) {
- arguments = [...arguments].map(arg => +arg);
- const calcDiscountedPricePerItem = (price, percentage) => price - price * (1 - percentage);
- const gpuPrice = 250;
- const cpuPricePercentage = 0.35;
- const ramPricePercentage = 0.1;
- const gpuPercentageDiscount = 0.15;
- const totalGpuPrice = videoCardCount * gpuPrice;
- const totalCpuPrice = processorsCount * calcDiscountedPricePerItem(totalGpuPrice, cpuPricePercentage);
- const totalRamPrice = ramMemoryCount * calcDiscountedPricePerItem(totalGpuPrice, ramPricePercentage);
- let totalSum = totalGpuPrice + totalCpuPrice + totalRamPrice;
- if (videoCardCount > processorsCount) {
- totalSum *= 1 - gpuPercentageDiscount;
- }
- const cost = budget - totalSum;
- if (cost >= 0) {
- console.log(`You have ${cost.toFixed(2)} leva left!`);
- } else {
- console.log(`Not enough money! You need ${(-cost).toFixed(2)} leva more!`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement