Hey, welcome back.
This is going to be a quick lesson, how you can use functions to construct objects.
So here we've got a quick example of how we're constructing an object, using a function.
So we've got CONSED and the variable name or the object name that's going to contain the object information.
And then we're passing through this object information.
So setting new car and then the function car is taking in these arguments and updating the this value
with the corresponding values within the arguments.
So the objective of this lesson is to try this out and get more familiar with it.
What I want you to do for the challenge is to make some objects using functions to return those values,
just like the example that we have.
And I'll walk you through it so you can go ahead and pause the video and try it out.
And I'll show you the solution coming up.
So first of all, let's create our function.
And this function can just be called car, and it's going to take in a bunch of parameters.
Then within the function, we're using this color and we're setting it to whatever the value of color,
we're using this Miles, setting it to whatever the value of miles is.
And lastly, let's do this company and setting it to value of company.
So next, let's create the object.
So using the mycar one.
And the flexibility here is that if you've got some more complex functionality or complex structure
that you needed within your object, you have the ability to build that in an unless let's make it pink.
And will console lock out my car, so it works the same way.
And if we want it to add to my car, we have the option to do that.
So if I wanted to add in a price and then we want to output my car, you're going to see that it works
the same way now.
So this is just a regular object and it functions the same way as we would expect for an object.
And you can construct multiple objects this way.
So if you've got another car and maybe this one is a Ford and this one is purple, and then you can
reference it within the console and see that we've constructed another object.
So this is another option when you are using functions in order to construct objects.
So go ahead and try this out.