Advertisement
Spocoman

08. Fuel Tank

Dec 18th, 2021 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fuelTank(input) {
  2.     let fuel = input[0].toLowerCase();
  3.     let liter = Number(input[1]);
  4.  
  5.     if (fuel == 'diesel' || fuel == 'gasoline' || fuel == 'gas') {
  6.         if (liter >= 25) {
  7.             console.log(`You have enough ${fuel}.`);
  8.         } else {
  9.             console.log(`Fill your tank with ${fuel}!`);
  10.         }
  11.     } else {
  12.         console.log('Invalid fuel!');
  13.     }
  14. }
  15.  
  16. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  17.  
  18. function fuelTank(input) {
  19.     let fuel = input[0].toLowerCase();
  20.     let liter = Number(input[1]);
  21.  
  22.     console.log(fuel == "diesel" || fuel == "gasoline" || fuel == "gas" ?
  23.         (liter >= 25 ? `You have enough ${fuel}.` : `Fill your tank with ${fuel}!`) : 'Invalid fuel!');
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement