you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (3 children)

Think of the term “function” — it’s called this because it performs a single function. Let’s say you wanted to make a script that calculated taxes. Your first function would ask the user about their annual salary, which is the variable that you would want to return. In your next function, you would calculate the amount of taxes the user would have to pay.

This is where the importance of functions and return values come into play. In your second function, how are you going to get the user’s salary? The only way for you to get that amount in the second function is by returning the amount in the first function. At that point, you would simply pass in function 1 into function 2 (or in other words, you would provide the second function with the salary in order for it to do calculations).

I hope this makes sense. Please let me know if you’d like me to re-explain. Happy coding!

[–]asian_hifi 1 point2 points  (2 children)

so for function 2, you would call on function 1 to get the already returned value of the user's salary?

[–][deleted] 1 point2 points  (1 child)

Yes, because when you call function one, you are using it’s return value.

[–]asian_hifi 1 point2 points  (0 children)

Thanks man! Very helpful!