Advertisement
Spocoman

04. Transport Price

Dec 18th, 2021 (edited)
45
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 time = input[1];
  4.     let price = 0;
  5.  
  6.     if (km < 20) {
  7.         if (time == "day") {
  8.             price = km * 0.79 + 0.7;
  9.         } else {
  10.             price = km * 0.9 + 0.7;
  11.         }
  12.     }  else if (km >= 100) {
  13.         price = km * 0.06;
  14.     }else {
  15.         price = km * 0.09;
  16.     }
  17.  
  18.     console.log(`${price.toFixed(2)}`);
  19. }
  20.  
  21. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  22.  
  23. function transportPrice(input) {
  24.     let km = Number(input[0]);
  25.     let time = input[1];
  26.  
  27.     let price = km < 20 ? km * (time == "day" ? 0.79 : 0.9) + 0.7 : km >= 100 ? km * 0.06 : km * 0.09;
  28.  
  29.     console.log(`${price.toFixed(2)}`);
  30. }
  31.  
  32. Или леко тарикатската:
  33.  
  34. function transportPrice(input) {
  35.     let km = Number(input[0]);
  36.  
  37.     console.log(`${(km < 20 ? km * (input[1] == "day" ? 0.79 : 0.9) + 0.7 : km >= 100 ? km * 0.06 : km * 0.09).toFixed(2)}`);
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement