To set up your project for this challenge the first thing I want you to do is to head over to your console 1
and while nodemon is running you can see that we don't have our prompt, our dollar sign right? 2
So that means the server is running using nodemon. 3
I want you to type rs and hit enter. 4
And what this does is it forces nodemon to restart, 5
that's what rs stands for, and what that means is that it will rerun apps.js which if you remember 6
will make our posts array become an empty array again. 7
So it deletes any of the posts that we currently have in our home page. 8
And from this blank slate I want you to head over to compose and to create a single blog post that has 9
the title of Test. And it's really important that you have the same title as I have here. 10
And then inside the post you can write any sort of mumbojumbo or simply head over to Lorem Ipsum and 11
put in some Lorem Ipsum text in there. 12
So now we have a single blog post. 13
Now here comes the goal of the challenge. 14
Now we know that we already have this post with a title of text stored inside our post array. 15
And you can refresh the page a couple of times just to make sure that it's definitely there 16
and we haven't emptied out our post array when we updated our app.js. 17
The aim of this challenge is if we can type /posts/test spelt out exactly the 18
same as the title of our blog post, 19
then when I hit enter and I go over to our console I should be able to see match found. 20
So I want you to write the code inside app.js that checks whether if this parameter value is equal 21
to a title of a post that we've got inside our posts array. 22
And if that's true then you're going to log match found. 23
Simple as that. And your code has to work even if the word is different 24
right? So it'll be /posts/testing. 25
And when I hit enter it should say match found. 26
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
post title. 28
I'm not changing its casing and I'm also not adding two words right? 29
We're going to deal with that a little bit later on. 30
Pause the video and see if you can complete this challenge. 31
Now the first hint is instead of console logging the value of the post name which were getting through 32
the URL as a parameter value, 33
I want you to save it into a variable. 34
So say something like const requestedTitle is equal to req.params.postName. 35
So now we can check this requestedTitle against all of the titles inside our posts array. 36
Now try out the challenge again and see if this hint helps you to complete it. 37
All right so here comes 38
hint number 2. 39
Now remember that our posts is an array 40
right? It's an array of post objects and post objects look like this. 41
They have two key value pairs, one that's called title and one that's called content. 42
What we need to do here in order to complete the challenge is we need to check if our requestedTitle 43
matches against any of the titles inside our posts array. 44
But because it's an array, we have to loop through the array in order to reach each and every post object 45
to check its title. 46
Remember how we used arrays in the past and see if this hint now helps you to complete the challenge.