Section 1 - Instruction

Last time, we learned how functions can receive information through parameters. But what if we want a function to give information back to us after it's done working?

Engagement Message

Imagine asking a calculator to add numbers - wouldn't you want the answer back?

Section 2 - Instruction

Functions can return values using the return keyword. When a function returns something, it sends that value back to wherever the function was called from.

Engagement Message

What do you think this function gives back?

Section 3 - Instruction

To capture what a function returns, we assign the function call to a variable. The returned value gets stored in that variable for us to use later.

Engagement Message

See how we "caught" the returned value?

Section 4 - Instruction

Not all functions need to return values. Functions that just print messages or perform actions without giving back data don't need return statements.

Engagement Message

Can you spot the difference in how these might be used?

Section 5 - Instruction

Here's a practical example. This function calculates if someone gets a discount:

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal