1
00:00:00,390 --> 00:00:07,830
When we create objects, generally, it reflects a real object where there is content that has a natural

2
00:00:07,830 --> 00:00:09,050
grouping together.

3
00:00:09,390 --> 00:00:14,940
So if we take something that when we look out the window, we see a car, a car is a great example of

4
00:00:14,940 --> 00:00:15,650
an object.

5
00:00:15,900 --> 00:00:18,600
So all the cars relatively the same.

6
00:00:18,600 --> 00:00:21,780
They're all going to have four tires, but each one of these cars.

7
00:00:21,900 --> 00:00:26,310
So one might be a different make, like a Mustang a might be a different brand as well.

8
00:00:26,460 --> 00:00:27,840
There's different colors.

9
00:00:27,930 --> 00:00:28,950
There's different years.

10
00:00:28,950 --> 00:00:34,080
They're made, there's different values that they have some different costs, prices as well as they

11
00:00:34,080 --> 00:00:39,960
might have some different functions or methods that they are able to do, that some of the other cars

12
00:00:39,960 --> 00:00:41,210
might not be able to do.

13
00:00:41,460 --> 00:00:47,670
And so this is ideal when you think of objects in order to place all of that information into an object

14
00:00:47,670 --> 00:00:49,930
format that then you can utilize.

15
00:00:50,280 --> 00:00:53,400
So the objective of this lesson is to try this out.

16
00:00:53,730 --> 00:01:00,900
So look at the car that we've got below, create an object around that car and then add in the functionality

17
00:01:00,900 --> 00:01:07,470
where if we do my car drive, then it says it returns back in the console.

18
00:01:07,470 --> 00:01:16,080
I'm driving Mustang referencing the make vroom vroom and then also add in a park method where we can

19
00:01:16,080 --> 00:01:23,250
do the my car park and then it can say the Mustang is parking or the Ford is parking and use some of

20
00:01:23,280 --> 00:01:25,410
the values that are contained within the object.

21
00:01:25,650 --> 00:01:27,240
So you can pause the video here.

22
00:01:27,390 --> 00:01:30,090
Try this out and I'll walk you through the solution.

23
00:01:30,090 --> 00:01:36,150
Coming up, I hope you had an opportunity to construct that car and you could use another car, too,

24
00:01:36,150 --> 00:01:37,960
if you didn't want to use the Mustang, of course.

25
00:01:38,250 --> 00:01:42,600
So first of all, we need to clear the myCar object so it's got nothing in it.

26
00:01:42,720 --> 00:01:45,000
Now, there's a number of ways that you could have accomplished this.

27
00:01:45,000 --> 00:01:50,880
You could have had this all in one, or you could have had the mycar creating that main container object

28
00:01:50,880 --> 00:01:52,130
and then add to it.

29
00:01:52,140 --> 00:01:53,700
So that's the way that I'm going to do it.

30
00:01:54,060 --> 00:01:55,680
I'm going to add in color.

31
00:01:56,310 --> 00:01:59,590
And either way, that would have been correct if you did it either way.

32
00:01:59,970 --> 00:02:02,430
So in this case, we're just going to do it on separate lines.

33
00:02:02,430 --> 00:02:03,680
So we've got my car.

34
00:02:03,840 --> 00:02:04,770
What else did we have?

35
00:02:04,770 --> 00:02:06,420
We had Brand as well.

36
00:02:06,660 --> 00:02:11,040
So the brand for it is a Ford and then my car.

37
00:02:11,670 --> 00:02:14,550
And we'll also do a make and the make of this.

38
00:02:15,160 --> 00:02:21,510
So we've got a lot of information that's contained within the my car and it's all relevant.

39
00:02:21,510 --> 00:02:25,140
It's all within that same grouping.

40
00:02:25,140 --> 00:02:28,230
And it's really easily to see how this fits together.

41
00:02:28,410 --> 00:02:34,770
So let's say you want it to get information about the car and you want to get a bunch of different cars.

42
00:02:34,810 --> 00:02:38,500
You want to get the prices of those, the mix of them and so on.

43
00:02:38,790 --> 00:02:44,040
So this is where the logic of when you create these objects that you can group things together.

44
00:02:44,130 --> 00:02:48,480
And this is where you got to think of it logically, how you can group things together and how all of

45
00:02:48,480 --> 00:02:50,280
this information can fit together.

46
00:02:50,760 --> 00:02:53,970
So we did have some values here.

47
00:02:53,970 --> 00:02:57,120
So we've got a color brand, Mieke, so let's try that out.

48
00:02:57,390 --> 00:03:02,880
And usually I do like to try it out in the console just to make sure that things are working as expected.

49
00:03:03,030 --> 00:03:06,780
So so we've got all this information being dropped into the object.

50
00:03:07,050 --> 00:03:10,800
So the other part of this challenge, so of course, there was a two part to this challenge.

51
00:03:10,950 --> 00:03:15,950
And the other part is to add in some methods and we did want one to drive.

52
00:03:16,320 --> 00:03:21,690
So this is setting up that anonymous function and then doing whatever you want it to run.

53
00:03:21,690 --> 00:03:25,170
So the block of code that you want to run is contained within this function.

54
00:03:25,680 --> 00:03:28,200
And for this time, we're not going to be returning anything.

55
00:03:28,200 --> 00:03:34,730
We're just putting it into the console so we can use template literal again as well as we did before.

56
00:03:34,860 --> 00:03:36,060
So I have a message.

57
00:03:36,060 --> 00:03:40,980
So I'm driving and then let's add in the make.

58
00:03:41,190 --> 00:03:47,760
And that's the nice thing about it, is that we can reference this and return back all the information

59
00:03:47,760 --> 00:03:49,530
that we've got contained within the object.

60
00:03:49,770 --> 00:03:56,730
So we've got this make I'm driving where it should say, driving my Mustang because you're driving it

61
00:03:57,150 --> 00:04:03,060
and then you can have you could use any any piece of information that's contained up here.

62
00:04:03,420 --> 00:04:07,010
And then we just simply had vroom vroom.

63
00:04:07,020 --> 00:04:09,300
So I think that's what a sound a car makes there.

64
00:04:09,630 --> 00:04:10,740
So we've got the drive.

65
00:04:10,860 --> 00:04:15,420
And then there was one more that we wanted to add in, and that was my car park.

66
00:04:15,450 --> 00:04:17,250
And so, again, anonymous function.

67
00:04:17,460 --> 00:04:20,280
And what block of code do you want to run within this function?

68
00:04:20,280 --> 00:04:25,830
So we just want to have a console message and I'll use the template literals against a little batiks

69
00:04:25,830 --> 00:04:26,070
there.

70
00:04:26,580 --> 00:04:34,800
And we can say parking the car or instead of car, let's use some of the information contained within

71
00:04:34,800 --> 00:04:37,200
the object so we can use this.

72
00:04:37,200 --> 00:04:45,210
Let's use parking the Ford now, go into the console and see what's contained within the car.

73
00:04:45,210 --> 00:04:49,230
So you've got all of this information, plus you've got the two methods as well.

74
00:04:49,620 --> 00:04:52,950
So let's try one of those methods and one was drive.

75
00:04:53,190 --> 00:04:56,100
And so don't forget to include the rounded brackets.

76
00:04:56,250 --> 00:04:57,900
Otherwise you're not going to invoke the function.

77
00:04:57,910 --> 00:04:59,760
So it's just going to return back that function.

78
00:05:00,110 --> 00:05:05,270
That's not what we want, we want to make sure that we invoke the function and we see I'm driving my

79
00:05:05,270 --> 00:05:09,290
Mustang, vroom, vroom, and maybe we could even add a few more O's there.

80
00:05:09,290 --> 00:05:11,810
So it makes it a little bit more powerful.

81
00:05:12,440 --> 00:05:13,940
Let's try the other one as well.

82
00:05:13,950 --> 00:05:19,340
So we've got my car and park and see what happens parking the Ford.

83
00:05:19,520 --> 00:05:21,280
So everything is working perfectly.

84
00:05:21,620 --> 00:05:23,840
So go ahead, try the suit, get familiar with it.

85
00:05:24,020 --> 00:05:25,370
You can even challenge yourself.

86
00:05:25,370 --> 00:05:32,150
Add in some more information contained within the car and as well add in some additional methods in

87
00:05:32,150 --> 00:05:34,430
order to get a fully functional car.

88
00:05:34,630 --> 00:05:40,490
You can also change the car as well and have different functions, different values.

89
00:05:40,610 --> 00:05:46,220
And we're going to be revisiting this later on when we look at more object oriented programming.

90
00:05:46,700 --> 00:05:49,670
So for now, get familiar with creating this type of object.
