Advertisement
desito07

Fuel Tank - Part 2

Apr 3rd, 2020
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. function fuelTank2(input) {
  2. let fuel = input.shift();
  3. let liters = +input.shift();
  4. let card = input.shift();
  5.  
  6. let price = 0;
  7.  
  8. if (fuel === "Gas") {
  9. price = 0.93;
  10. if (card === "Yes") {
  11. price -= price * 0.08;
  12. }
  13. } else if (fuel === "Gasoline") {
  14. price = 2.22;
  15. if (card === "Yes") {
  16. price -= price * 0.18;
  17. }
  18. } else if (fuel === "Diesel") {
  19. price = 2.33;
  20. if (card === "Yes") {
  21. price -= price * 0.12;
  22. }
  23. }
  24. if (liters >= 20 && liters <= 25) {
  25. price -= price * 0.08;
  26. } else if (liters > 25) {
  27. price -= price * 0.1;
  28. }
  29. price1 = price * liters;
  30. console.log(`${price1.toFixed(2)} lv.`);
  31. }
  32. fuelTank2(["Gas", "30", "Yes"]);
  33. fuelTank2(["Gasoline", "25", "No"]);
  34. fuelTank2(["Diesel", "19", "No"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement