All language subtitles for 042 Challenge 20 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
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's the answer to this challenge.

Now in order to solve this challenge you have to remember that programmers don't memorize things.

Instead we always search for what it is that we need and the skill is being able to apply it to your

current problem.

Good old Google.

I'm going to start off by searching inside Google for what it is that I want and it tends to be verb

object and the programming language that I use.

So in this case I want to truncate a string using Javascript.

This is a good format to use whenever you're trying to solve problems.

Don't have anything that's really specific in here.

Say if I just said truncate string to 100 characters, then I would limit my search to only the people

who explained how to truncate a string to 100 characters right?

Somebody might have wanted to do it for 20 characters or 5 characters. So don't have anything specific

in there, just have a verb, an object

and the programming language and that tends to work pretty well.

So let's explore the first answer.

And it seems like this person also just want to truncate something using pure Javascript down to a set

number of characters.

Now the first answer explains to you that you can use the substring method and they very kindly link to

the documentation. And you can see that here if you have a variable that say hello world which is a string

then you can use the substring method on that string in order to cut it down.

So in this case if we're saying that we want to cut it down from 1 to 4, then remember that programming

starts from 0

so we would take the first character of our Hello world

so at this position, and then we would end up the fourth character.

So if I now hit Try it you can see that I just get ell . And if I change this to say 0 and 3 then

I will start from the beginning and I'll only take the first three characters.

So now if I hit run and hit Try it, then I only get Hel.

So let's apply this substring method to our code to make it do what we want.

The part that we want to truncate is our post.content and we want to do it inside our home.ejs

where we got access to each and every post's content. Right at the end here

I'm going to tag on that method substring and then I need to specify a from and a to.

So the from is going to be from the very beginning,

so the zeroth character and the end is going to be at the 100th character,

so 0 - 100. And then at the end of all of this string, I'm going to append or add onto it space and then

...

And this should indicate to the reader that this is truncated

and if they wanted to read more than they have to click on something.

So let's hit save. And we head back to our home page and we hit refresh

then you should see that all of our blog posts are now truncated down to only 100 characters and we

just have that ... at the end to show that there's actually more. To complete this entire module

there is only one more challenge.

So I'll see over there.

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