1
00:00:01,040 --> 00:00:01,920
Hey, welcome back.

2
00:00:01,950 --> 00:00:05,850
This is going to be a quick lesson, how you can use functions to construct objects.

3
00:00:06,050 --> 00:00:11,150
So here we've got a quick example of how we're constructing an object, using a function.

4
00:00:11,180 --> 00:00:17,450
So we've got CONSED and the variable name or the object name that's going to contain the object information.

5
00:00:17,570 --> 00:00:20,110
And then we're passing through this object information.

6
00:00:20,300 --> 00:00:29,300
So setting new car and then the function car is taking in these arguments and updating the this value

7
00:00:29,300 --> 00:00:32,360
with the corresponding values within the arguments.

8
00:00:32,840 --> 00:00:37,000
So the objective of this lesson is to try this out and get more familiar with it.

9
00:00:37,520 --> 00:00:43,430
What I want you to do for the challenge is to make some objects using functions to return those values,

10
00:00:43,610 --> 00:00:45,440
just like the example that we have.

11
00:00:45,650 --> 00:00:48,890
And I'll walk you through it so you can go ahead and pause the video and try it out.

12
00:00:49,100 --> 00:00:51,230
And I'll show you the solution coming up.

13
00:00:51,380 --> 00:00:53,630
So first of all, let's create our function.

14
00:00:54,110 --> 00:00:59,240
And this function can just be called car, and it's going to take in a bunch of parameters.

15
00:01:00,260 --> 00:01:06,510
Then within the function, we're using this color and we're setting it to whatever the value of color,

16
00:01:06,850 --> 00:01:12,270
we're using this Miles, setting it to whatever the value of miles is.

17
00:01:12,850 --> 00:01:18,210
And lastly, let's do this company and setting it to value of company.

18
00:01:18,670 --> 00:01:20,610
So next, let's create the object.

19
00:01:20,620 --> 00:01:23,020
So using the mycar one.

20
00:01:23,230 --> 00:01:29,980
And the flexibility here is that if you've got some more complex functionality or complex structure

21
00:01:29,980 --> 00:01:36,430
that you needed within your object, you have the ability to build that in an unless let's make it pink.

22
00:01:37,740 --> 00:01:42,180
And will console lock out my car, so it works the same way.

23
00:01:42,390 --> 00:01:46,650
And if we want it to add to my car, we have the option to do that.

24
00:01:48,170 --> 00:01:54,590
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

25
00:01:54,590 --> 00:01:55,320
the same way now.

26
00:01:55,340 --> 00:02:00,950
So this is just a regular object and it functions the same way as we would expect for an object.

27
00:02:01,220 --> 00:02:04,930
And you can construct multiple objects this way.

28
00:02:04,970 --> 00:02:13,310
So if you've got another car and maybe this one is a Ford and this one is purple, and then you can

29
00:02:13,310 --> 00:02:17,200
reference it within the console and see that we've constructed another object.

30
00:02:17,540 --> 00:02:22,540
So this is another option when you are using functions in order to construct objects.

31
00:02:22,550 --> 00:02:23,750
So go ahead and try this out.
