1
00:00:00,500 --> 00:00:06,470
This lesson, we're going to be exploring the JavaScript object method and looking at how objects work

2
00:00:06,470 --> 00:00:12,620
and what arrays are and how we can output the value of an object to an array and some more information

3
00:00:12,620 --> 00:00:18,710
about in general about objects so you can run functions that are contained within objects.

4
00:00:18,960 --> 00:00:23,950
So as you can see in this example, we're returning back a value for the person first.

5
00:00:23,960 --> 00:00:24,800
So we're turning back.

6
00:00:24,820 --> 00:00:30,260
Hello and whatever the value of person first is, and we can also update these objects.

7
00:00:30,590 --> 00:00:34,810
So now the challenge in this lesson is to take what we did earlier.

8
00:00:34,820 --> 00:00:40,340
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

9
00:00:40,340 --> 00:00:48,170
before and add in methods that we can invoke with JavaScript, that we can turn the car on and drive

10
00:00:48,290 --> 00:00:53,810
and then output the messages as those actions are being taken place into the console.

11
00:00:53,930 --> 00:00:58,610
I'll give you a quick sneak peek how to do this and you can pause the video.

12
00:00:58,610 --> 00:01:01,010
I'll walk you through the solution coming up.

13
00:01:01,400 --> 00:01:04,960
Well, let's set up our car object some values.

14
00:01:04,970 --> 00:01:08,590
We've got color of red and come a separate those out.

15
00:01:08,600 --> 00:01:16,100
So maybe we have a top speed for this car and that can be three hundred and 300 miles, 300 kilometers.

16
00:01:16,340 --> 00:01:18,440
Not quite sure at this point what it is.

17
00:01:18,840 --> 00:01:20,620
Let's give it model.

18
00:01:20,630 --> 00:01:24,710
So this can be a Mustang since it sounds like it's going to go super fast.

19
00:01:25,070 --> 00:01:30,590
Give it another value here so you can add as many as necessary here.

20
00:01:30,710 --> 00:01:32,300
And this is just a combination.

21
00:01:32,310 --> 00:01:36,080
So we've got no we've got some strings.

22
00:01:36,410 --> 00:01:38,390
And let's also add in one more number.

23
00:01:38,400 --> 00:01:41,210
So we've got a price value for the car.

24
00:01:41,630 --> 00:01:44,810
And now let's go to adding in the methods.

25
00:01:45,030 --> 00:01:52,240
So we wanted to add in a method where we do something such as turn it on and then this can equal a function.

26
00:01:52,580 --> 00:01:54,380
We're not going to take in any parameters.

27
00:01:54,590 --> 00:02:02,390
We're going to consider log out that this car is start it looks add in one more where we've got drive

28
00:02:03,080 --> 00:02:09,040
again, creating the function, the anonymous function and then outputting into the console.

29
00:02:09,050 --> 00:02:15,500
Let's console log that you are driving and now we are ready to try this.

30
00:02:15,500 --> 00:02:17,900
So go and go into your console.

31
00:02:18,360 --> 00:02:21,830
You can see within my car all the values that we have available to us.

32
00:02:22,040 --> 00:02:29,630
So if we do my car and we do drive invoking the function, we're running the block of code and we're

33
00:02:29,630 --> 00:02:32,060
being returned back that you are driving.

34
00:02:32,510 --> 00:02:38,630
Also, maybe we want to take some information that's contained within this object so we can reference

35
00:02:38,630 --> 00:02:41,440
the information from the object itself.

36
00:02:41,450 --> 00:02:43,100
I'm going to just concatenate it together.

37
00:02:43,100 --> 00:02:49,040
So if we want it to this, if we do the my car, you Mustang driving.

38
00:02:49,040 --> 00:02:55,190
So it's taking the information and notice as well that we can use this in order to reference the current

39
00:02:55,940 --> 00:02:56,660
object.

40
00:02:56,870 --> 00:03:01,610
So instead of doing the my car dot model, we can use this DOT model.

41
00:03:01,760 --> 00:03:06,590
So this also provides us some more flexibility when we're writing out our code and we're creating our

42
00:03:06,590 --> 00:03:06,920
code.

43
00:03:06,920 --> 00:03:12,350
And before we conclude, there's actually one other way that we can have methods in here and then to

44
00:03:12,350 --> 00:03:16,100
consider log, but we can do it within this format as well.

45
00:03:16,100 --> 00:03:21,530
So if we list out the value of my car, you're going to see at the end we've got one called works.

46
00:03:21,530 --> 00:03:22,490
This is a function.

47
00:03:22,700 --> 00:03:29,090
So it understands that this is a function and I can do my car works and invoke the function and we can

48
00:03:29,090 --> 00:03:31,310
see that that block a code gets run as well.

49
00:03:31,520 --> 00:03:32,930
So that's another option.

50
00:03:33,170 --> 00:03:37,730
But typically, I do like to do this type of format where we've got the anonymous function and then

51
00:03:37,730 --> 00:03:40,580
we've got the block, a code that's being run in between there.
