svephoto

Shopping [JavaScript]

May 13th, 2021
577
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calc(input) {
  2.     let peterBudget = Number(input[0]);
  3.     let numberGPUs = Number(input[1]);
  4.     let numberCPUs = Number(input[2]);
  5.     let numberRAMs = Number(input[3]);
  6.  
  7.     let gpusPrice = numberGPUs * 250;
  8.     let cpusPrice = gpusPrice * 0.35;
  9.     let ramsPrice = gpusPrice * 0.10;
  10.  
  11.     let total = gpusPrice + (numberCPUs * cpusPrice) + (numberRAMs * ramsPrice);
  12.  
  13.     if (numberGPUs >= numberCPUs) {
  14.         total = total * 0.85;  
  15.     }
  16.  
  17.     if (total <= peterBudget) {
  18.         console.log(`You have ${(peterBudget - total).toFixed(2)} leva left!`);
  19.     } else {
  20.         console.log(`Not enough money! You need ${(total - peterBudget).toFixed(2)} leva more!`);
  21.     }
  22. }
  23.  
RAW Paste Data