If functions are like recipes, then arguments are like ingredients.
Functions can take in values to work with, similar to how recipes call for different ingredients.
There are two functions in the editor:
returnNumbers function takes a single argument named
num. You can see it between the parentheses.
addNumbers function takes two arguments:
num2. Multiple arguments are separated by commas.
If you change the ingredients in a recipe, you change the result. The same thing happens when you change the arguments to a function.
returnNumber with different numbers:
Notice that the function itself doesn't change, but when we change the arguments passed into the function, we change the result of the function.
Now try calling the second function with different arguments:
The value of
num2 become whatever values we pass into the function.
Once we name an argument in the function parentheses, we can use that name to work with the argument inside the function.
function, and argument names can't start with a number.
We should give arguments names that describe what the argument is or does. If an argument is a number,
number are good names. If the argument is a specific type of number like a person's age or the number of apples we have, we should be more specific. Good names for those arguments could be