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
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French Download
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
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,450 --> 00:00:00,680 All right. 2 00:00:00,690 --> 00:00:03,740 So here's the answer to this challenge. 3 00:00:03,930 --> 00:00:09,020 Now in order to solve this challenge you have to remember that programmers don't memorize things. 4 00:00:09,030 --> 00:00:15,120 Instead we always search for what it is that we need and the skill is being able to apply it to your 5 00:00:15,120 --> 00:00:16,580 current problem. 6 00:00:16,590 --> 00:00:17,390 Good old Google. 7 00:00:17,400 --> 00:00:22,950 I'm going to start off by searching inside Google for what it is that I want and it tends to be verb 8 00:00:23,040 --> 00:00:26,300 object and the programming language that I use. 9 00:00:26,730 --> 00:00:31,510 So in this case I want to truncate a string using Javascript. 10 00:00:31,530 --> 00:00:34,680 This is a good format to use whenever you're trying to solve problems. 11 00:00:34,770 --> 00:00:37,290 Don't have anything that's really specific in here. 12 00:00:37,290 --> 00:00:45,150 Say if I just said truncate string to 100 characters, then I would limit my search to only the people 13 00:00:45,300 --> 00:00:48,930 who explained how to truncate a string to 100 characters right? 14 00:00:48,930 --> 00:00:54,360 Somebody might have wanted to do it for 20 characters or 5 characters. So don't have anything specific 15 00:00:54,360 --> 00:00:57,360 in there, just have a verb, an object 16 00:00:57,450 --> 00:01:01,350 and the programming language and that tends to work pretty well. 17 00:01:01,350 --> 00:01:04,050 So let's explore the first answer. 18 00:01:04,379 --> 00:01:10,440 And it seems like this person also just want to truncate something using pure Javascript down to a set 19 00:01:10,440 --> 00:01:11,930 number of characters. 20 00:01:11,940 --> 00:01:18,030 Now the first answer explains to you that you can use the substring method and they very kindly link to 21 00:01:18,030 --> 00:01:24,360 the documentation. And you can see that here if you have a variable that say hello world which is a string 22 00:01:24,750 --> 00:01:30,390 then you can use the substring method on that string in order to cut it down. 23 00:01:30,390 --> 00:01:37,650 So in this case if we're saying that we want to cut it down from 1 to 4, then remember that programming 24 00:01:37,650 --> 00:01:39,260 starts from 0 25 00:01:39,450 --> 00:01:43,760 so we would take the first character of our Hello world 26 00:01:43,770 --> 00:01:47,930 so at this position, and then we would end up the fourth character. 27 00:01:48,000 --> 00:01:58,230 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 28 00:01:58,260 --> 00:02:02,880 I will start from the beginning and I'll only take the first three characters. 29 00:02:02,910 --> 00:02:06,880 So now if I hit run and hit Try it, then I only get Hel. 30 00:02:06,900 --> 00:02:12,820 So let's apply this substring method to our code to make it do what we want. 31 00:02:12,900 --> 00:02:18,360 The part that we want to truncate is our post.content and we want to do it inside our home.ejs 32 00:02:18,660 --> 00:02:23,300 where we got access to each and every post's content. Right at the end here 33 00:02:23,310 --> 00:02:31,290 I'm going to tag on that method substring and then I need to specify a from and a to. 34 00:02:31,590 --> 00:02:34,080 So the from is going to be from the very beginning, 35 00:02:34,080 --> 00:02:39,100 so the zeroth character and the end is going to be at the 100th character, 36 00:02:39,180 --> 00:02:47,610 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 37 00:02:47,610 --> 00:02:48,460 ... 38 00:02:48,570 --> 00:02:52,530 And this should indicate to the reader that this is truncated 39 00:02:52,530 --> 00:02:55,430 and if they wanted to read more than they have to click on something. 40 00:02:55,680 --> 00:03:01,550 So let's hit save. And we head back to our home page and we hit refresh 41 00:03:01,650 --> 00:03:07,740 then you should see that all of our blog posts are now truncated down to only 100 characters and we 42 00:03:07,740 --> 00:03:14,710 just have that ... at the end to show that there's actually more. To complete this entire module 43 00:03:14,760 --> 00:03:17,010 there is only one more challenge. 44 00:03:17,010 --> 00:03:18,110 So I'll see over there. 4607

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