ProdanTenev

FuelTankPart2

Feb 11th, 2022 (edited)
1,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.71 KB | None | 0 0
  1. function fuelTank(input) {
  2.     let gasoline = 2.22;
  3.     let diesel = 2.33;
  4.     let gas = 0.93;
  5.     let fuelType = String(input[0]);
  6.     let quantity = Number(input[1]);
  7.     let discountCard = String(input[2]);
  8.     let gasolinePrice = 0;
  9.     let dieselPrice = 0;
  10.     let gasPrice = 0;
  11.     if (discountCard === "Yes" && fuelType === "Gasoline") {
  12.         gasoline -= 0.18;
  13.     } else if (discountCard === "Yes" && fuelType === "Diesel") {
  14.         diesel -= 0.12;
  15.     } else if (discountCard === "Yes" && fuelType === "Gas") {
  16.         gas -= 0.08;
  17.     } else {
  18.         gasoline = 2.22;
  19.         diesel = 2.33;
  20.         gas = 0.93;
  21.     }
  22.     if (fuelType === "Gasoline") {
  23.         if (quantity >= 20 && quantity <= 25) {
  24.             gasolinePrice = (gasoline * quantity) * 0.92;
  25.         } else if (quantity > 25){
  26.             gasolinePrice = (gasoline * quantity) * 0.9;
  27.         } else {
  28.             gasolinePrice = gasoline * quantity;
  29.         }
  30.         console.log(`${gasolinePrice.toFixed(2)} lv.`);
  31.     } else if (fuelType === "Diesel") {
  32.         if (quantity >= 20 && quantity <= 25) {
  33.             dieselPrice = (diesel * quantity) * 0.92;
  34.         } else if (quantity > 25) {
  35.             dieselPrice = (diesel * quantity) * 0.9;
  36.         } else {
  37.             dieselPrice = diesel * quantity;
  38.         }
  39.         console.log(`${dieselPrice.toFixed(2)} lv.`);
  40.     } else if (fuelType === "Gas") {
  41.         if (quantity >= 20 && quantity <= 25) {
  42.             gasPrice = (gas * quantity) * 0.92;
  43.         } else if (quantity > 25) {
  44.             gasPrice = (gas * quantity) * 0.9;
  45.         } else {
  46.             gasPrice = gas * quantity;
  47.         }
  48.         console.log(`${gasPrice.toFixed(2)} lv.`);        
  49.     }
  50. }
Add Comment
Please, Sign In to add comment