...

Exercise: Fuel Tank Capacity

Welcome to the Rocket Fuel Calculation mission! 🚀

Our astronauts are preparing to return to Earth, but we need to calculate the total amount of fuel available in the rocket's two fuel tanks.

In this lesson, you'll write a program that:

  • Asks the user for the amount of fuel in the first fuel tank using the prompt function.
  • Asks the user for the amount of fuel in the second fuel tank using the prompt function.
  • Adds the two amounts together to calculate the total fuel available.
  • Prints the total fuel available to the console using console.log.

However, there's a catch! User input from the prompt function is always a string. If you don't convert the inputs to numbers, the + operator will concatenate the inputs as strings instead of adding them as numbers.

You can run the associated code sample to see what happens when you forget to convert the inputs to numbers. Then, fix the code to calculate the correct total fuel available!

You can refer to the following code sample from the previous exercise for an example of how to do this:

let convertedNum1 = Number(num1);
let convertedNum2 = Number(num2);
let sum = convertedNum1 + convertedNum2;
Loading...

Output (Console)