Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.4 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69272dcf1c24b44fd79137c4 Challenge 141: Takeoff Fuel 28 challenge-141

--description--

Given the numbers of gallons of fuel currently in your airplane, and the required number of liters of fuel to reach your destination, determine how many additional gallons of fuel you should add.

  • 1 gallon equals 3.78541 liters.
  • If the airplane already has enough fuel, return 0.
  • You can only add whole gallons.
  • Do not include decimals in the return number.

--hints--

fuelToAdd(0, 1) should return 1.

assert.equal(fuelToAdd(0, 1), 1);

fuelToAdd(5, 40) should return 6.

assert.equal(fuelToAdd(5, 40), 6);

fuelToAdd(10, 30) should return 0.

assert.equal(fuelToAdd(10, 30), 0);

fuelToAdd(896, 20500) should return 4520.

assert.equal(fuelToAdd(896, 20500), 4520);

fuelToAdd(1000, 50000) should return 12209.

assert.equal(fuelToAdd(1000, 50000), 12209);

--seed--

--seed-contents--

function fuelToAdd(currentGallons, requiredLiters) {

  return currentGallons;
}

--solutions--

function fuelToAdd(currentGallons, requiredLiters) {
  const litersPerGallon = 3.78541;
  const currentLiters = currentGallons * litersPerGallon;
  if (currentLiters >= requiredLiters) return 0;
  const litersNeeded = requiredLiters - currentLiters;
  return Math.ceil(litersNeeded / litersPerGallon);
}