Now because we are returning a value now,
we're now a bit more independent when it comes to that
total adult years variable, but there still,
is another external variable,
which we are using in calculate adult years.
And that will be this age.
This is still a variable, which we define
outside of this function and then redefine here.
And again, we typically want to avoid referencing
and using such external variables here.
Now, in case of the result, which we derived,
we could solve the problem by returning.
But what can we do in case of some
input value which we're using?
For this use case, we have a feature
called function parameters.
Function parameters are basically inputs we can
accept in a function.
And for those, we need to those parentheses here,
directly after the function name
Here, we can accept parameters
and we can give those parameters any name of our choice
and we can use as many as we need.
Now here, I'm only interested in the age
and to avoid name duplication,
even though it's technically would be allowed,
but to avoid confusion, I'll choose a different name here.
I'll name it "User Age"
It's like to finding a variable, but without
the let keyword, but following the same
naming conventions as we had them for variables.
So this name is up to you,
but should follow those rules and conventions.
This is now a parameter of this function
and inside of this function code.
So between these curly braces, it acts as a variable
that's only accessible inside of this function.
So not outside of this function.
We can't use user age here that won't work.
It's only available inside of this function.
And we cannot use that in our calculation
instead of age we can use user age.
Now, like that it would not work though.
Instead, now that we added this parameter
when we call the function,
we have to pass a value for that parameter.
And maybe you're already guessing it,
that's what we do between the parentheses here,
when we call a function.
That's also what we're doing for alert already.
Alert is a built in function provided by the browser that
takes a parameter actually.
And we're passing in a value for that parameter
here in that case the value which we want to
output in the alert.
In case of our own function, we also want such a parameter
and we want a parameter that we use in this
mathematical calculation. So we want the age of the user.
And therefore, here, when we call calculate adult years,
we can, of course, just pass in a value,
which we create on the fly, so to say.
Or we use an existing variable, like age year.
This age variable, which I created up here.
I can use that down there as well,
and pass that value into this function, when we execute
this function.
And here we also pass an age
and that's the great thing about functions and
why they are so useful.
Especially if you do use parameters and return values.
Now we define our general code once,
but it's pretty flexible.
We can call this function with different values for age,
as we're doing it here.
The value of age changes between these two function calls
and we'll get back different results.
Our general logic, our algorithm is always the same,
but the concrete values change because we're using this
parameter of value here.
Now, of course you can only pass in a value
for this parameter that makes sense for this function.
So for example, passing in a text like, "Hi there"
doesn't make a lot of sense.
"Hi there" minus 18, which is the operation that
would be performed, doesn't lead to anything useful
But since you are the one writing your functions,
and you're the one calling your functions,
or if you're working in a team,
you are passing on the information on how this function
should be used, you of course know how to call it.
And that, that in this case, we should pass in a number,
for example, the number stored in our age variable.
And with all of that, if we save this and it reloads,
we again, get these alert boxes with 14 and 27.
Now this function only needs one parameter.
If we would need multiple parameters and other functions
could need multiple parameters. For example,
in an upcoming exercise for you,
you will have a function with multiple parameters,
then you can separate them with commas.
So that would be another parameter here,
separated by a comma. The names are always up to you,
but you have to separate them with commas.
Now, here, we don't need it,
but it is something you should know because you will
definitely also sometimes write functions that do need more
than one parameter.
And now with that,
we are using all those amazing function features you should
know about.