WEBVTT 0 00:00.360 --> 00:00.690 All right. 1 00:00.700 --> 00:03.060 So here's the answer to the challenge. 2 00:03.180 --> 00:09.480 Now if you had any trouble trying to figure out how to create an object in Javascript then you would've 3 00:09.570 --> 00:13.490 come across the syntax for an object that looks something like this. 4 00:13.530 --> 00:18.180 So you would start with the keyword var to show that you're creating a new variable, then you would give 5 00:18.180 --> 00:21.270 that variable a name whatever it is that you wish, 6 00:21.430 --> 00:25.780 then you have an equal sign and you open a set of curly braces. 7 00:25.860 --> 00:33.050 Now inside the curly braces you have your key value pairs and you can have as many pairs as you wish 8 00:33.390 --> 00:39.540 and you can even nest key value pairs as the value for a particular key. 9 00:39.540 --> 00:46.770 So in this case the key and values that are in red is actually bunched together as a value for the second 10 00:46.770 --> 00:47.360 key. 11 00:47.580 --> 00:55.320 So with this refresher on Javascript objects in mind let's head over to our app.js and let's delete 12 00:55.380 --> 01:02.970 this console that log. And instead of console logging our post body and post title we're going to store 13 01:02.970 --> 01:05.390 it inside a object. 14 01:05.400 --> 01:08.950 Let's use the same syntax as we saw previously in the slides. 15 01:09.120 --> 01:15.000 So that's create a var and we'll call it a post and we're going to use the equal sign and then we to open 16 01:15.000 --> 01:16.640 up a set of curly braces. 17 01:16.980 --> 01:22.090 And this is the start of any Javascript object. Inside the curly braces 18 01:22.110 --> 01:24.810 I'm going to put in my key value pairs. 19 01:24.810 --> 01:30.210 So the two keys that I want are the title and the content. 20 01:30.240 --> 01:36.570 Now all I have to do is just to add the values of each of those keys. So we know that the content is 21 01:36.570 --> 01:37.630 basically this 22 01:37.650 --> 01:38.370 right? 23 01:38.400 --> 01:39.750 It's request. 24 01:39.750 --> 01:43.700 body.postBody. 25 01:43.870 --> 01:51.800 And- So the title is structured very similarly request.body.postTitle and then we have a comma 26 01:51.830 --> 01:58.850 separating our key value pairs and we complete object by closing it off with a semicolon. 27 01:58.850 --> 02:06.470 So now we can delete our console.log and we now have our brand new object that's called post that contains 28 02:06.470 --> 02:09.400 two key value pairs separated by a comma, 29 02:09.590 --> 02:16.380 one is going to be the title and one is going to be the content. And these values are passed over 30 02:16.520 --> 02:19.820 when that post route is triggered. 31 02:20.030 --> 02:26.390 Now the final thing to consider is that we mentioned previously that you should try to avoid using vars 32 02:26.450 --> 02:27.940 if at all possible. 33 02:28.130 --> 02:35.120 And the best type of programming practice is to start with the most restrictive type of variable which 34 02:35.120 --> 02:36.490 is a const. 35 02:36.560 --> 02:43.370 And as you remember consts cannot be changed after they've been created. And we're not planning on 36 02:43.370 --> 02:49.280 changing it inside here after it's been declared. We're only interested in storing it and then we'll 37 02:49.280 --> 02:52.350 use it inside one of our pages. 38 02:52.790 --> 02:58.880 So a const is probably the best keyword to put over here. Now if you use the var or if you use the let, 39 02:59.030 --> 03:05.430 that's completely fine. But just take a refresher of what we talked about in the scope lesson and 40 03:05.590 --> 03:09.230 when we mentioned these three types of variables. 41 03:09.230 --> 03:11.720 So now we're ready to move on to the next challenge.