freeCodeCamp Challenge Guide: Multiply Two Decimals with JavaScript

Multiply Two Decimals with JavaScript


Problem Explanation

JavaScript uses the * symbol for multiplication. Multiplying floats is the same as multiplying integers. JavaScript only has the number type, which serves both integer and floating point numbers, it does not have a specific type for integers.

For example, if you were to multiply 2 integers, the numbers 3 and 5, then you could simply type:

var product = 3 * 5; // product is 15

Now if we were to multiply two floating point numbers, 3.4 and 5.7, the product would be a float as well:

var product = 3.4 * 5.7; // product is 19.38

Hints

Hint 1

Think about what decimal number, when multiplied by 2.0, would equal 5.0.


Solutions

Solution 1 (Click to Show/Hide)
var product = 2.0 * 2.5; // product is 5.0 because 2.5 * 2.0 = 5.0

More Information