curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68b06e589bf2273243814777.md
Given the size of a fuel tank, the current fuel level, and the price per gallon, return the cost to fill the tank all the way.
tankSize is the total capacity of the tank in gallons.fuelLevel is the current amount of fuel in the tank in gallons.pricePerGallon is the cost of one gallon of fuel."$d.dd".costToFill(20, 0, 4.00) should return "$80.00".
assert.equal(costToFill(20, 0, 4.00), "$80.00");
costToFill(15, 10, 3.50) should return "$17.50".
assert.equal(costToFill(15, 10, 3.50), "$17.50");
costToFill(18, 9, 3.25) should return "$29.25".
assert.equal(costToFill(18, 9, 3.25), "$29.25");
costToFill(12, 12, 4.99) should return "$0.00".
assert.equal(costToFill(12, 12, 4.99), "$0.00");
costToFill(15, 9.5, 3.98) should return "$21.89".
assert.equal(costToFill(15, 9.5, 3.98), "$21.89");
function costToFill(tankSize, fuelLevel, pricePerGallon) {
return tankSize;
}
function costToFill(tankSize, fuelLevel, pricePerGallon) {
let gallonsNeeded = tankSize - fuelLevel;
let cost = gallonsNeeded * pricePerGallon;
return `$${cost.toFixed(2)}`;
}