Spocoman

Family Trip

Feb 21st, 2022 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function familyTrip(input) {
  2.     let budget = Number(input[0]);
  3.     let overnight = Number(input[1]);
  4.     let overnightPrice = Number(input[2]);
  5.     let additionalCosts = Number(input[3]);
  6.  
  7.     if (overnight > 7) {
  8.         overnightPrice *= 0.95;
  9.     }
  10.  
  11.     let totalPrice = overnight * overnightPrice + additionalCosts * budget / 100;
  12.  
  13.     if (totalPrice > budget) {
  14.         console.log(`${(totalPrice - budget).toFixed(2)} leva needed.`);
  15.     } else {
  16.         console.log(`Ivanovi will be left with ${(budget - totalPrice).toFixed(2)} leva after vacation.`);
  17.     }
  18. }
  19.  
  20. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  21.  
  22. function familyTrip(input) {
  23.     let budget = Number(input[0]);
  24.     let overnight = Number(input[1]);
  25.     let overnightPrice = Number(input[2]);
  26.     let additionalCosts = Number(input[3]);
  27.  
  28.     budget -= overnight * (overnight > 7 ? 0.95 : 1) * overnightPrice + (additionalCosts * budget) / 100;
  29.  
  30.     console.log(
  31.         budget < 0 ?
  32.         `${Math.abs(budget).toFixed(2)} leva needed.` :
  33.         `Ivanovi will be left with ${budget.toFixed(2)} leva after vacation.`
  34.     );
  35. }
  36.  
Add Comment
Please, Sign In to add comment