All language subtitles for 036 Challenge 17 Solution_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

All right so here comes the answer.

Now we know that we can tap into whatever value the user typed into here

after that forward slash by tapping into req.params. the name of that parameter which is

postName right?

So let's go ahead and instead of console logging it, let's save that into a variable.

Now let's say something like var requestedTitle is equal to req.params.postName.

The next thing we need to do is we need to compare this requestedTitle against all the titles that

we have inside our posts array

right?

So we know that posts is an array that contains a bunch of post objects.

So each object has two key value pairs, a title and a content and the title inside this object is what

we need to tap into.

But because we only have access to this posts array in order to access each individual post we have

to loop through the array.

Fortunately we already know how to do that and how to do that quite easily.

We can use our trusty forEach method in order to loop through each of the posts inside the post array.

So if you remember the syntax was we specify the thing that we wanted to loop through which is our post

array with an S at the end.

This is the plural form.

And then we call forEach on that array. And then we open up a set of parentheses and we put in an anonymous

function. Inside the parameters of the function we specify the singular form of our array object.

So that in this case is a single post

right? Without the 's'. And now we open up a set of curly brackets and inside here we now have access to

each and individual post inside our post array .

That means that we can store this other variable which is called storedTitle and this is going to be

equal to the post.title.

So what our loop does currently is it will loop through all of the posts inside our post array

and for each post, it's going to save it into a variable called storeTitle.

Now some of your developer instincts should be tingling by now as we mentioned we should always start from

const and then work upwards to let and var as needed.

So let's go ahead and change that to const and change that to const. And you'll notice that we actually

don't change the value of either of these inside the curly braces.

These both work fine for our purposes.

So now we have the requested title and each stored title Inside our array.

Now it's time to check for each post

whether if the storedTitle matches the requestedTitle so we can use an IF statement for that.

And we check to see if storedTitle === the requestedTitle.

Then in that case we're going to log match found.

And now this is all the code that we need to loop through each of our posts, store each of the titles

inside a constant called storeTitle and then we check if the storedTitle matches with the requested

title

and if so, we log match found.

So let's go ahead and check it out.

So once you resave our app.js you might notice that our home page is again devoid of any blog posts.

Now in future modules, we're going to figure out how to fix this.

But in order to do that we need to learn about databases and that's not the focus of this module.

So let's just work with it as it is for now.

And let's head over to compose and create a new post that again has the title of Test and then some

Lorem Ipsum as the content.

So now we know that we have this post called Test.

And no matter how much we refresh, it still saved currently in our server.

Let's go ahead to posts/Test and I'm going to spell it exactly the same way in terms

of capitalization as the title of my post. And once I hit enter, you can see in your console that we get

match found.

If I go ahead and add another post...

and I write Day 1, then you can see again we get match found.

That's the solution to this challenge.

If you've struggled with this challenge depending on which part you found difficult I recommend reviewing

the lessons that covered those aspects.

There's a couple of things that might have tripped you up around here.

One is using the forEach to loop through our array which we covered previously in challenge 14.

Or it might be that you got tripped up by the Express routing parameters which we covered just before

challenge 16.

So either pause the video and re-explore those topics that you find difficult or if this was a breeze,

then continue on to the next challenge.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.