Advertisement
svephoto

Transport Price [JavaScript]

Dec 14th, 2021 (edited)
1,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function transportPrice(input) {
  2.     let km = Number(input[0]);
  3.     let trip = input[1];
  4.    
  5.     let taxiInitialTax = 0.70
  6.     let taxiDayTariff = 0.79;
  7.     let taxiNightTariff = 0.90;
  8.     let bus = 0.09;
  9.     let train = 0.06;
  10.  
  11.     let totalTransportPrice = 0;
  12.  
  13.     if (km >= 100) {
  14.         totalTransportPrice = train * km;
  15.     } else if (km >= 20) {
  16.         totalTransportPrice = bus * km;
  17.     } else {
  18.         if (trip == "day") {
  19.             totalTransportPrice = taxiDayTariff * km + taxiInitialTax;
  20.         } else {
  21.             totalTransportPrice = taxiNightTariff * km + taxiInitialTax;
  22.         }
  23.     }
  24.  
  25.     console.log(totalTransportPrice.toFixed(2));
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement