borisova936935

Untitled

Oct 9th, 2021
85
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 videoCardsCount = Number(input[1]);
  4.   let processorsCount = Number(input[2]);
  5.   let ramCount = Number(input[3]);
  6.  
  7.   let videocardPrice = videoCardsCount * 250;
  8.   let processorsPrice = processorsCount * (videocardPrice * 0.35);
  9.   let ramPrice = ramCount * (videocardPrice * 0.1);
  10.  
  11.   let sum = videocardPrice + processorsPrice + ramPrice;
  12.  
  13.   if (videoCardsCount > processorsCount) {
  14.     sum *= 0.85;
  15.   }
  16.   let diff = Math.abs(budget - sum);
  17.  
  18.   if (budget >= sum) {
  19.     console.log(`You have ${diff.toFixed(2)} leva left!`);
  20.   } else {
  21.     console.log(`Not enough money! You need ${diff.toFixed(2)} leva more!`);
  22.   }
  23. }
  24. shopping(["920.45", "3", "1", "1"]);
  25.  
Advertisement
Add Comment
Please, Sign In to add comment