Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
All right.
So here comes Challenge 20. Currently on our home page it's quite cluttered because every single blog post
no matter how long it is one paragraph or five paragraphs,
it all gets listed here.
But now that we've managed to create a separate page for each and every single one of our blog posts
we don't want to list it in full on our home page anymore.
The goal of this challenge is to use Google and use Stack Overflow and use all the resources you have
on the Internet to figure out how you can change the code so that our home page now truncates the content
of each blog posts to only 100 characters. And then at the end there's just these three ...
and now we only have a preview of each blog post.
Pause the video and I want you to practice this really truly important programming skill of figuring
things out by yourself and try to complete this challenge.
So here's my first hint for you.
A journey of a thousand miles starts with a single step.
The programmer version of that is that the journey of solving any programming problem starts with a single
search.
So let's go ahead and try to succinctly explain to Google what it is that we want to know.
Now the goal that we want to achieve is to be able to truncate our string down to 100 characters using
Javascript.
So if we exclude all of the specific parts of our problem say the 100 characters right? Because somebody
else might have posted that they wanted to limit it to 10 characters.
So to widen our search let's try something like
truncate string Javascript. And the first answer we get on Stack Overflow
let's check it out.
Let's see what that query is to see if it matches our own.
So they want to truncate a dynamically loaded string using straight Javascript and all they care about
is just the number of characters.
That sounds exactly like what we want to do as well.
And the answer they explain is to use the substring method and they actually very kindly link to the
documentation as well as providing a code example.
So let's say that you have a string ABCDEFG and you want to truncate it down to say only 3 characters
long. Then you would say the string
call a method .substring on it and then inside the parentheses you specify a start position and an
end position where you want to cut up that string.
So now the outcome of my truncated string is now just ABC because it goes from 0 to length which is 3.
So from 0 to 3 then then that includes 0, 1, 2, 3 only has ABC right?
So now using this
can you apply it to the challenge and solve it for yourself?
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.