Advertisement
Liliana797979

shopping

Feb 18th, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function shopping(input) {
  2.     let budget = Number(input[0]);
  3.     let videoCardCount = Number(input[1]);
  4.     let processorsCount = Number(input[2]);
  5.     let ramMemoryCount = Number(input[3]);
  6.     let totalPrice = 0;
  7.  
  8.     let videoCardPrice = 250 * videoCardCount;
  9.     let processorsPrice = (videoCardPrice * 0.35) * processorsCount;
  10.     let ramMemoryPrice = (videoCardPrice * 0.10) * ramMemoryCount;
  11.    
  12.  
  13.     totalPrice = videoCardPrice + processorsPrice + ramMemoryPrice;
  14.  
  15.     if (videoCardCount > processorsCount) {
  16.         totalPrice = totalPrice * 0.85;
  17.  
  18.         if (budget >= totalPrice) {
  19.             console.log(`You have ${(budget - totalPrice).toFixed(2)} leva left!`);
  20.         } else {
  21.             console.log(`Not enough money! You need ${(totalPrice - budget).toFixed(2)} leva more!`);
  22.         }
  23.     }
  24. }
  25.  
  26. shopping(["920.45", "3", "1", "1"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement