Returning Values from a Function

Learn how to return values from a function.

Trapped in the function

Previously, we saw how writing code for calculating time into a function is a much better way. But we do have a problem. The result from the calculation is trapped within the function. By “trapped,” we mean that we calculate the correct number of seconds, but the value obtained can’t get out of the function, so there’s no way for us to use this value outside of it. To solve this problem, we’ll need to return the result back out to the caller. Let’s see how this works.

Get hands-on with 1200+ tech skills courses.