Now we know about methods.
And I did want to talk about methods right now, already,
because whilst we for the moment
won't define our own methods too often,
we will actually work with quite a bit of built in methods
throughout this and the next sections.
And here's a good example: up to this point,
I always used alert for outputting something.
And the advantage is that we do see that right here on the
screen, in this alert box.
The disadvantage is that we always
have to click it away and so on.
And since this is all just a dummy example anyways,
to get started with Java script and learn these basics,
this of course is not code that does anything useful,
which we would need on a real page.
Since that's the case,
it would be nice to not have this alert,
but instead we have this console here
in the developer tools, this console tab.
And we did see that in here,
we get error messages that might be caused by our code.
Well, it turns out that
we cannot just see possible error messages
of which we hopefully don't have too many,
but we can also actively
output data and information into this console.
We can log data into this console.
So that we see it here.
And during development for learning Java script
and for playing around with it, that's great.
It's quicker and simply easier to use,
than working with that alert box.
Now for that, we will use a built in object
provided by the browser and a method
that's built into this object out of the box.
And I'll start here, when I first alert something.
Instead of calling this alert command,
which has all that built in, I will now remove that,
and instead use the built in console variable in the end,
it's provided by the browser,
which turns out to store an object.
Hence we can use the dot notation here.
And now we see there are a bunch of methods built in.
You learned these purple boxes,
which are shaped like this, are methods.
We also have one property here.
Now for us, the log method is very useful.
So here I'll select this by clicking on it.
And now as it's a method,
we execute it by adding parentheses.
Now this log method wants a parameter value
and we can see this. If I hover over it,
we see that it's a method.
And then this part here all looks a bit strange,
but in the end, that means that
it takes a flexible amount of parameters.
It's not something we have learned about yet,
but it means it takes parameters.
That's all we need to know for now.
And then this part here void simply means that that's a
method that won't return any value.
Void means this method or this function
does not return anything.
That's how we can read this.
And since it takes parameters,
we can pass total adult years as a parameter,
we can see that it's takes any kind of value.
That's what this means.
So passing in a number,
which total adult years will be, should be fine.
And we can do this here as well.
Replace alert with console.log,
and also here in our agreed method,
replace alert with console.log.
We can use this built in variable and method inside of our
own method, that works without issues.
And as a side note,
if you now hover over your own method here,
you also get some explanation here by visual studio code.
We see that it's a method and that this also doesn't return
anything because we have no return statement in there,
and that we take no parameters.
On the other hand for a calculate adult years,
We see that we need an age.
Here the type is anything which is technically not correct,
but visual studio code doesn't understand
that we need a number in there,
but we see that it will return a number in the end,
because we returned a result of this calculation.
That's just a side note, but also useful to use
when you want to find out how you can execute your own
or built in methods and functions, but back to console.log,
I'm now using console.log
in all the places where I used alert.
And if I now a save that, you see that now after reloading,
you get this output here in this console tab
in your browser dev tools,
and that's more convenient than
having to deal with these alerts.
And if you reload this page,
you get this output again, and here you see
two numbers and then some text, the text is white,
the numbers are purple, in my case,
when using this dark mode.
And that's how we use a built in variable,
which holds an object, which has this log method.
And that's why I wanted to introduce methods,
because console.log is just
one example of a built-in method, which we'll use a lot.
We'll use it a lot to output information without using
alert, which is more disturbing and a bit more annoying.
Of course, I want to emphasize again,
that console.log is producing output,
which we only see in these developer tools
and the typical user of our page,
Of course, won't see them.
Everyone could open these tools,
but no one typically does that.
It's just there for us to practice JavaScript.
We will do more useful things with JavaScript later,
once we've learned a bit more about it.