Spocoman

07. Shopping

Dec 16th, 2021 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function shopping(input) {
  2.  
  3.     let budget = parseFloat(input[0]);
  4.     let gpu = parseInt(input[1]);
  5.     let cpu = parseInt(input[2]);
  6.     let ram = parseInt(input[3]);
  7.  
  8.     let gpuPrice = gpu * 250;
  9.     let cpuPrice = cpu * gpuPrice * 0.35;
  10.     let ramPrice = ram * gpuPrice * 0.10;
  11.                      
  12.     let totalAmount = gpuPrice + cpuPrice + ramPrice;
  13.  
  14.     if (gpu > cpu){
  15.         totalAmount *= 0.85;
  16.     }
  17.     if (budget >= totalAmount){
  18.         console.log(`You have ${(budget - totalAmount).toFixed(2)} leva left!`);
  19.     } else{
  20.         console.log(`Not enough money! You need ${(totalAmount - budget).toFixed(2)} leva more!`);
  21.     }
  22.  
  23. }
  24.  
Add Comment
Please, Sign In to add comment