JavaScript JavaScript Basics Creating Reusable Code with Functions Random Number Challenge Solution

Tre Bu
Tre Bu
1,521 Points

Why is the return needed?

When Dave does return Math.floor....

Why do you need the return? I know when you do not use the return in the console it will say that line is undefined when you call the function, but I do not see why the return is necessary.

1 Answer

Steven Parker
Steven Parker
173,522 Points

It's the "return" statement that passes the value back to point in the code where the function was called. Any function that ends without using a "return" statement will always have a value of "undefined".