This lesson, we're going to be exploring the JavaScript object method and looking at how objects work
and what arrays are and how we can output the value of an object to an array and some more information
about in general about objects so you can run functions that are contained within objects.
So as you can see in this example, we're returning back a value for the person first.
So we're turning back.
Hello and whatever the value of person first is, and we can also update these objects.
So now the challenge in this lesson is to take what we did earlier.
So if you used a car and if you haven't used a car, you can grab one of the car objects that we have
before and add in methods that we can invoke with JavaScript, that we can turn the car on and drive
and then output the messages as those actions are being taken place into the console.
I'll give you a quick sneak peek how to do this and you can pause the video.
I'll walk you through the solution coming up.
Well, let's set up our car object some values.
We've got color of red and come a separate those out.
So maybe we have a top speed for this car and that can be three hundred and 300 miles, 300 kilometers.
Not quite sure at this point what it is.
Let's give it model.
So this can be a Mustang since it sounds like it's going to go super fast.
Give it another value here so you can add as many as necessary here.
And this is just a combination.
So we've got no we've got some strings.
And let's also add in one more number.
So we've got a price value for the car.
And now let's go to adding in the methods.
So we wanted to add in a method where we do something such as turn it on and then this can equal a function.
We're not going to take in any parameters.
We're going to consider log out that this car is start it looks add in one more where we've got drive
again, creating the function, the anonymous function and then outputting into the console.
Let's console log that you are driving and now we are ready to try this.
So go and go into your console.
You can see within my car all the values that we have available to us.
So if we do my car and we do drive invoking the function, we're running the block of code and we're
being returned back that you are driving.
Also, maybe we want to take some information that's contained within this object so we can reference
the information from the object itself.
I'm going to just concatenate it together.
So if we want it to this, if we do the my car, you Mustang driving.
So it's taking the information and notice as well that we can use this in order to reference the current
object.
So instead of doing the my car dot model, we can use this DOT model.
So this also provides us some more flexibility when we're writing out our code and we're creating our
code.
And before we conclude, there's actually one other way that we can have methods in here and then to
consider log, but we can do it within this format as well.
So if we list out the value of my car, you're going to see at the end we've got one called works.
This is a function.
So it understands that this is a function and I can do my car works and invoke the function and we can
see that that block a code gets run as well.
So that's another option.
But typically, I do like to do this type of format where we've got the anonymous function and then
we've got the block, a code that's being run in between there.