WEBVTT 0 00:00.120 --> 00:05.650 To set up your project for this challenge the first thing I want you to do is to head over to your console 1 00:05.800 --> 00:10.370 and while nodemon is running you can see that we don't have our prompt, our dollar sign right? 2 00:10.370 --> 00:13.320 So that means the server is running using nodemon. 3 00:13.320 --> 00:16.170 I want you to type rs and hit enter. 4 00:16.410 --> 00:20.370 And what this does is it forces nodemon to restart, 5 00:20.370 --> 00:26.880 that's what rs stands for, and what that means is that it will rerun apps.js which if you remember 6 00:26.940 --> 00:30.920 will make our posts array become an empty array again. 7 00:30.930 --> 00:35.430 So it deletes any of the posts that we currently have in our home page. 8 00:35.610 --> 00:41.070 And from this blank slate I want you to head over to compose and to create a single blog post that has 9 00:41.070 --> 00:46.240 the title of Test. And it's really important that you have the same title as I have here. 10 00:46.500 --> 00:52.620 And then inside the post you can write any sort of mumbojumbo or simply head over to Lorem Ipsum and 11 00:52.620 --> 00:56.010 put in some Lorem Ipsum text in there. 12 00:56.190 --> 00:59.260 So now we have a single blog post. 13 00:59.280 --> 01:01.640 Now here comes the goal of the challenge. 14 01:01.650 --> 01:09.140 Now we know that we already have this post with a title of text stored inside our post array. 15 01:09.450 --> 01:13.290 And you can refresh the page a couple of times just to make sure that it's definitely there 16 01:13.470 --> 01:17.560 and we haven't emptied out our post array when we updated our app.js. 17 01:18.030 --> 01:27.540 The aim of this challenge is if we can type /posts/test spelt out exactly the 18 01:27.540 --> 01:30.960 same as the title of our blog post, 19 01:30.990 --> 01:38.010 then when I hit enter and I go over to our console I should be able to see match found. 20 01:38.010 --> 01:46.650 So I want you to write the code inside app.js that checks whether if this parameter value is equal 21 01:46.950 --> 01:51.870 to a title of a post that we've got inside our posts array. 22 01:52.170 --> 01:55.160 And if that's true then you're going to log match found. 23 01:55.170 --> 02:00.420 Simple as that. And your code has to work even if the word is different 24 02:00.420 --> 02:05.010 right? So it'll be /posts/testing. 25 02:05.810 --> 02:08.450 And when I hit enter it should say match found. 26 02:08.490 --> 02:15.180 Now at this point we're not too worried yet about the casing so I'm typing it exactly as I see as the 27 02:15.180 --> 02:16.310 post title. 28 02:16.320 --> 02:21.300 I'm not changing its casing and I'm also not adding two words right? 29 02:21.300 --> 02:23.830 We're going to deal with that a little bit later on. 30 02:23.860 --> 02:27.430 Pause the video and see if you can complete this challenge. 31 02:29.450 --> 02:37.220 Now the first hint is instead of console logging the value of the post name which were getting through 32 02:37.230 --> 02:39.600 the URL as a parameter value, 33 02:39.830 --> 02:42.950 I want you to save it into a variable. 34 02:43.010 --> 02:53.600 So say something like const requestedTitle is equal to req.params.postName. 35 02:53.630 --> 03:02.640 So now we can check this requestedTitle against all of the titles inside our posts array. 36 03:02.660 --> 03:06.940 Now try out the challenge again and see if this hint helps you to complete it. 37 03:09.150 --> 03:10.020 All right so here comes 38 03:10.020 --> 03:11.320 hint number 2. 39 03:12.640 --> 03:16.500 Now remember that our posts is an array 40 03:16.510 --> 03:22.360 right? It's an array of post objects and post objects look like this. 41 03:22.360 --> 03:27.670 They have two key value pairs, one that's called title and one that's called content. 42 03:27.670 --> 03:33.970 What we need to do here in order to complete the challenge is we need to check if our requestedTitle 43 03:34.360 --> 03:38.570 matches against any of the titles inside our posts array. 44 03:38.800 --> 03:45.730 But because it's an array, we have to loop through the array in order to reach each and every post object 45 03:46.060 --> 03:48.370 to check its title. 46 03:48.370 --> 03:54.640 Remember how we used arrays in the past and see if this hint now helps you to complete the challenge.