0 1 00:00:00,120 --> 00: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 2 00:00:05,800 --> 00:00:10,370 and while nodemon is running you can see that we don't have our prompt, our dollar sign right? 2 3 00:00:10,370 --> 00:00:13,320 So that means the server is running using nodemon. 3 4 00:00:13,320 --> 00:00:16,170 I want you to type rs and hit enter. 4 5 00:00:16,410 --> 00:00:20,370 And what this does is it forces nodemon to restart, 5 6 00:00:20,370 --> 00: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 7 00:00:26,940 --> 00:00:30,920 will make our posts array become an empty array again. 7 8 00:00:30,930 --> 00:00:35,430 So it deletes any of the posts that we currently have in our home page. 8 9 00:00:35,610 --> 00: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 10 00:00:41,070 --> 00:00:46,240 the title of Test. And it's really important that you have the same title as I have here. 10 11 00:00:46,500 --> 00:00:52,620 And then inside the post you can write any sort of mumbojumbo or simply head over to Lorem Ipsum and 11 12 00:00:52,620 --> 00:00:56,010 put in some Lorem Ipsum text in there. 12 13 00:00:56,190 --> 00:00:59,260 So now we have a single blog post. 13 14 00:00:59,280 --> 00:01:01,640 Now here comes the goal of the challenge. 14 15 00:01:01,650 --> 00:01:09,140 Now we know that we already have this post with a title of text stored inside our post array. 15 16 00:01:09,450 --> 00:01:13,290 And you can refresh the page a couple of times just to make sure that it's definitely there 16 17 00:01:13,470 --> 00:01:17,560 and we haven't emptied out our post array when we updated our app.js. 17 18 00:01:18,030 --> 00:01:27,540 The aim of this challenge is if we can type /posts/test spelt out exactly the 18 19 00:01:27,540 --> 00:01:30,960 same as the title of our blog post, 19 20 00:01:30,990 --> 00:01:38,010 then when I hit enter and I go over to our console I should be able to see match found. 20 21 00:01:38,010 --> 00:01:46,650 So I want you to write the code inside app.js that checks whether if this parameter value is equal 21 22 00:01:46,950 --> 00:01:51,870 to a title of a post that we've got inside our posts array. 22 23 00:01:52,170 --> 00:01:55,160 And if that's true then you're going to log match found. 23 24 00:01:55,170 --> 00:02:00,420 Simple as that. And your code has to work even if the word is different 24 25 00:02:00,420 --> 00:02:05,010 right? So it'll be /posts/testing. 25 26 00:02:05,810 --> 00:02:08,450 And when I hit enter it should say match found. 26 27 00:02:08,490 --> 00: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 28 00:02:15,180 --> 00:02:16,310 post title. 28 29 00:02:16,320 --> 00:02:21,300 I'm not changing its casing and I'm also not adding two words right? 29 30 00:02:21,300 --> 00:02:23,830 We're going to deal with that a little bit later on. 30 31 00:02:23,860 --> 00:02:27,430 Pause the video and see if you can complete this challenge. 31 32 00:02:29,450 --> 00:02:37,220 Now the first hint is instead of console logging the value of the post name which were getting through 32 33 00:02:37,230 --> 00:02:39,600 the URL as a parameter value, 33 34 00:02:39,830 --> 00:02:42,950 I want you to save it into a variable. 34 35 00:02:43,010 --> 00:02:53,600 So say something like const requestedTitle is equal to req.params.postName. 35 36 00:02:53,630 --> 00:03:02,640 So now we can check this requestedTitle against all of the titles inside our posts array. 36 37 00:03:02,660 --> 00:03:06,940 Now try out the challenge again and see if this hint helps you to complete it. 37 38 00:03:09,150 --> 00:03:10,020 All right so here comes 38 39 00:03:10,020 --> 00:03:11,320 hint number 2. 39 40 00:03:12,640 --> 00:03:16,500 Now remember that our posts is an array 40 41 00:03:16,510 --> 00:03:22,360 right? It's an array of post objects and post objects look like this. 41 42 00:03:22,360 --> 00:03:27,670 They have two key value pairs, one that's called title and one that's called content. 42 43 00:03:27,670 --> 00:03:33,970 What we need to do here in order to complete the challenge is we need to check if our requestedTitle 43 44 00:03:34,360 --> 00:03:38,570 matches against any of the titles inside our posts array. 44 45 00:03:38,800 --> 00: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 46 00:03:46,060 --> 00:03:48,370 to check its title. 46 47 00:03:48,370 --> 00:03:54,640 Remember how we used arrays in the past and see if this hint now helps you to complete the challenge.