1
00:00:00,390 --> 00:00:05,640
Hey, remember the car from the earlier lesson, well, it's back and it's brought another car with

2
00:00:05,640 --> 00:00:05,820
it.

3
00:00:05,830 --> 00:00:09,390
So now we've got a Mustang and we've got a Honda Accord.

4
00:00:09,630 --> 00:00:14,640
So we've got several different cars and we relatively want them to do the same thing.

5
00:00:14,640 --> 00:00:16,350
But there are some differences.

6
00:00:16,530 --> 00:00:17,790
There's different models.

7
00:00:17,790 --> 00:00:19,260
There's different prices.

8
00:00:19,470 --> 00:00:23,010
So we want them to be able to do the same thing where we can drive it.

9
00:00:23,010 --> 00:00:26,430
But if we want to sell it, then there is a difference in the price as well.

10
00:00:26,670 --> 00:00:30,210
So we want some of the functionality to be the same and others to be different.

11
00:00:30,300 --> 00:00:36,060
And this is where we're going to be using objects and constructing objects, using the blueprint that

12
00:00:36,060 --> 00:00:37,230
we learned in the last lesson.

13
00:00:37,910 --> 00:00:38,790
So now it's your turn.

14
00:00:38,820 --> 00:00:44,010
You can pause the video and use what we learned in the last lesson with the blueprint and create two

15
00:00:44,010 --> 00:00:44,870
different cars.

16
00:00:44,880 --> 00:00:46,850
I'll show you the solution coming up.

17
00:00:46,860 --> 00:00:50,160
Let's go ahead and create our car constructor function.

18
00:00:50,170 --> 00:00:53,190
So creating the function and we're going to uppercase car.

19
00:00:53,640 --> 00:00:54,690
This is a constructor.

20
00:00:54,900 --> 00:00:58,820
And then we're going to take in the values that are going to be different for each one of the cars.

21
00:00:59,070 --> 00:01:05,370
So we've got color, brand, milk, price and year, and you might have a few other ones as well.

22
00:01:05,550 --> 00:01:07,560
So let's start with these and then coming in.

23
00:01:07,560 --> 00:01:14,610
And as we're constructing the object, we want to add in the color to equal to color and also have a

24
00:01:14,610 --> 00:01:17,040
brand and equal it to brand.

25
00:01:17,730 --> 00:01:22,420
Also make equal that to of course make makes sense to price.

26
00:01:23,160 --> 00:01:25,090
Now you don't have to name them the same as well.

27
00:01:25,350 --> 00:01:30,830
So now we've got a basic car that we've created and let's construct two different cars.

28
00:01:30,840 --> 00:01:34,710
So we've got one, we'll call it Honda and this is going to be new car.

29
00:01:34,740 --> 00:01:36,990
And then what are the values that we want to send in?

30
00:01:37,020 --> 00:01:39,600
So first is color, so we want to be red.

31
00:01:40,200 --> 00:01:42,300
The brand is going to be a Honda.

32
00:01:42,300 --> 00:01:44,670
The make of it is an accord.

33
00:01:44,670 --> 00:01:49,630
The price of the car is forty five thousand, say, and I have no idea how much it is.

34
00:01:49,640 --> 00:01:52,440
So I'm just doing a rough ballpark estimate.

35
00:01:52,460 --> 00:01:53,750
So forgive me if I'm wrong.

36
00:01:54,390 --> 00:01:59,250
Next, let's do the same thing for the Mustang and this one is an older Mustang.

37
00:01:59,250 --> 00:02:06,320
So the year is let's make just some adjustments here and maybe it's worth more money than a brand new

38
00:02:06,330 --> 00:02:06,800
accord.

39
00:02:06,820 --> 00:02:07,440
Not sure.

40
00:02:07,740 --> 00:02:13,260
And update the color to be black, the make of it.

41
00:02:13,470 --> 00:02:17,220
So it's up by Ford and the model is Mustang.

42
00:02:17,250 --> 00:02:18,090
So let's see what happens.

43
00:02:18,090 --> 00:02:18,750
Refresh.

44
00:02:18,750 --> 00:02:22,290
And now when we output Honda, let's see what we've got.

45
00:02:22,290 --> 00:02:24,090
We've got our car here.

46
00:02:24,090 --> 00:02:25,770
So we've got all of the information.

47
00:02:26,040 --> 00:02:29,220
And then, of course, we can make adjustments to it as well.

48
00:02:29,220 --> 00:02:33,600
So if you want just this year, we can adjust the year as well.

49
00:02:33,600 --> 00:02:36,710
And then look at Honda and you can see the year's changed.

50
00:02:36,900 --> 00:02:41,160
So we've got all of the flexibility and we can work with these values as needed.

51
00:02:41,370 --> 00:02:43,500
And also the same thing for Mustang.

52
00:02:43,510 --> 00:02:45,930
So we've got two different objects.

53
00:02:45,930 --> 00:02:50,200
So Honda and Mustang and we're essentially using that same template.

54
00:02:50,550 --> 00:02:54,540
So now let's take this one step further and add in some methods.

55
00:02:54,690 --> 00:02:56,190
And this is really the fun part.

56
00:02:56,190 --> 00:03:01,980
And this is where you see really the power of creating it this way, because you can create the method

57
00:03:02,100 --> 00:03:07,230
and use some of the values that are contained in here and really do some really cool things with it.

58
00:03:07,500 --> 00:03:10,290
So I'm going to just simply console lock outs.

59
00:03:10,290 --> 00:03:14,430
And in this case, we can use the tactics.

60
00:03:14,550 --> 00:03:15,730
And what do we want to say?

61
00:03:15,780 --> 00:03:23,000
Let's say I am driving my and then this is where we can add in the type of car.

62
00:03:23,460 --> 00:03:25,940
So this is this brand.

63
00:03:26,520 --> 00:03:29,040
So it's referencing whatever the current object is.

64
00:03:29,190 --> 00:03:35,370
So if we change it and also let me add in the year and I'll show you that we can make the updates and

65
00:03:35,370 --> 00:03:37,530
the changes and that we can use the year.

66
00:03:37,530 --> 00:03:43,200
So just as we saw earlier, where we've got the year coming out here where we're able to update it,

67
00:03:43,290 --> 00:03:45,740
it will also update within the method as well.

68
00:03:45,750 --> 00:03:48,330
And OK, let's add in vroom, vroom.

69
00:03:48,360 --> 00:03:50,620
So that's drive and let's refresh.

70
00:03:50,640 --> 00:03:55,290
So now we've got our Honda and let's drive the Honda and see what happens.

71
00:03:55,290 --> 00:03:57,990
I'm driving my 2020 Honda.

72
00:03:57,990 --> 00:03:58,740
Vroom, vroom.

73
00:03:59,280 --> 00:04:01,620
Let's take a Honda update our a year.

74
00:04:01,890 --> 00:04:05,850
And how about we make it 20, 40 and go back to drive.

75
00:04:05,850 --> 00:04:08,790
I'm driving by 2040.

76
00:04:08,790 --> 00:04:10,200
Honda Vroom Vroom.

77
00:04:10,230 --> 00:04:15,120
So this is in case you're watching the video way, way into the future in 20, 40.

78
00:04:15,130 --> 00:04:17,880
So that makes a little bit more sense at that time.

79
00:04:18,450 --> 00:04:23,210
Let's also add in a few other methods and you can have some fun with this, of course.

80
00:04:23,910 --> 00:04:29,930
It's really just designed to help you practice and get more familiar with what you can do with JavaScript.

81
00:04:30,240 --> 00:04:33,210
So another console message to use the tactics again.

82
00:04:33,420 --> 00:04:35,850
And this time we're parking the car.

83
00:04:35,850 --> 00:04:44,880
So parking the and we've already used let's instead of brand we'll use make and this shouldn't be drive.

84
00:04:44,880 --> 00:04:45,990
This should be park.

85
00:04:45,990 --> 00:04:49,080
So whatever actions you're taking, reference these methods.

86
00:04:49,290 --> 00:04:55,170
And also if we want to sell it like so what if we want to sell it, we want to maybe get a certain percentage

87
00:04:55,170 --> 00:04:58,040
of the price of the car that we paid for it.

88
00:04:58,470 --> 00:04:59,760
So I want to sell it.

89
00:05:00,090 --> 00:05:08,460
So let's make this one a little bit longer message I want to sell my for at least, and then this is

90
00:05:08,700 --> 00:05:16,080
where we can calculation if we want so we can take the price and multiply it by point nine or something

91
00:05:16,080 --> 00:05:19,760
like that for at least and put a dollar sign in front there.

92
00:05:20,010 --> 00:05:21,670
I know this is getting fairly long.

93
00:05:21,690 --> 00:05:27,320
Of course you can make your own since I paid and this is going to be the price again.

94
00:05:27,330 --> 00:05:29,340
So this is the price that they paid.

95
00:05:29,580 --> 00:05:33,450
And I want to get at least 90 percent of the value back.

96
00:05:33,840 --> 00:05:34,860
So see what this looks like.

97
00:05:34,870 --> 00:05:41,640
So Honda and if you want to sell the Honda, I want to sell my accord for at least forty thousand five

98
00:05:41,640 --> 00:05:45,360
hundred since I paid forty five hundred forty five thousand for it.

99
00:05:45,930 --> 00:05:52,320
Let's see what the Mustang is selling for and those same message calculations all done.

100
00:05:52,920 --> 00:05:54,960
Maybe I want to park my Mustang.

101
00:05:55,110 --> 00:05:57,060
So parking the Mustang.

102
00:05:57,870 --> 00:06:00,280
I want to also maybe park the Honda Accord.

103
00:06:00,300 --> 00:06:01,500
OK, I think you get the point.

104
00:06:01,590 --> 00:06:06,930
So go ahead, try the suit, get comfortable with creating and constructing these objects.

105
00:06:07,050 --> 00:06:12,270
And the nice thing about it is if all of a sudden you've got another car, all you need to do is enter

106
00:06:12,270 --> 00:06:15,250
in these parameters and the rest of the stuff is the same.

107
00:06:15,540 --> 00:06:21,960
So even if you had something like this and wheels and so we know that all of them will have four wheels.

108
00:06:22,110 --> 00:06:28,320
So you can set some default values here as well, that there's four wheels that's got a steering wheel,

109
00:06:28,320 --> 00:06:29,340
it's got a radio.

110
00:06:29,490 --> 00:06:32,340
So all of the stuff that would come standard within the car.

111
00:06:32,490 --> 00:06:37,950
And this makes it a lot easier than having to do the Honda and constructing all this stuff and then

112
00:06:37,950 --> 00:06:39,450
Mustang and all of this stuff.

113
00:06:39,450 --> 00:06:43,140
And if you have some changes, it's way, way easier doing it this way.
