All language subtitles for 14. Coding Challenge#2

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian Download
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 1 00:00:01,210 --> 00:00:04,710 Welcome to the second coding challenge. 2 2 00:00:04,710 --> 00:00:07,130 In this one you're gonna test your knowledge 3 3 00:00:07,130 --> 00:00:10,553 of the if/else statement that we just learned about. 4 4 00:00:12,220 --> 00:00:14,110 This coding challenge number two 5 5 00:00:14,110 --> 00:00:17,510 will basically improve the first challenge. 6 6 00:00:17,510 --> 00:00:20,420 We're still gonna be using DBMI example, 7 7 00:00:20,420 --> 00:00:24,430 but we are going to print a nice output to the console 8 8 00:00:24,430 --> 00:00:27,513 and this output is gonna tell us who has the higher BMI. 9 9 00:00:29,000 --> 00:00:30,810 The output message can be either 10 10 00:00:30,810 --> 00:00:33,770 Mark's BMI is higher than John's 11 11 00:00:33,770 --> 00:00:37,250 or John's BMI is higher than Mark's. 12 12 00:00:37,250 --> 00:00:38,420 That's the first part, 13 13 00:00:38,420 --> 00:00:41,700 and then as a second part use a template string 14 14 00:00:41,700 --> 00:00:45,653 to include the actual BMI values in the outputs. 15 15 00:00:47,040 --> 00:00:49,010 Okay, and as you can guess, 16 16 00:00:49,010 --> 00:00:51,940 you should probably use an if/else statement 17 17 00:00:51,940 --> 00:00:55,140 to complete this challenge, right? 18 18 00:00:55,140 --> 00:00:57,963 So, pause the video now and I'll see you in a second. 19 19 00:01:00,820 --> 00:01:02,000 All right. 20 20 00:01:02,000 --> 00:01:04,993 Again, I hope that you managed to do this. 21 21 00:01:07,610 --> 00:01:10,600 Let me show you how I did it. 22 22 00:01:10,600 --> 00:01:14,590 Let's start by getting this code from the other challenge, 23 23 00:01:14,590 --> 00:01:16,810 so coding challenge number one, 24 24 00:01:16,810 --> 00:01:21,513 because of course we don't have to repeat the same code. 25 25 00:01:24,930 --> 00:01:29,930 Here we have the mass and the height of both John and Mark, 26 26 00:01:30,307 --> 00:01:33,760 and we already have their BMIs calculated. 27 27 00:01:33,760 --> 00:01:38,760 We also have this condition here basically already, 28 28 00:01:38,820 --> 00:01:40,970 so this operation here already tells us 29 29 00:01:40,970 --> 00:01:44,503 whether Mark has a higher BMI or not, right? 30 30 00:01:45,403 --> 00:01:47,890 Let's get rid of this 31 31 00:01:48,990 --> 00:01:51,523 and let's write our if/else statement. 32 32 00:01:53,097 --> 00:01:56,014 If BMIMark is greater than BMIJohn, 33 33 00:02:00,208 --> 00:02:04,005 and here we could have just used this variable, 34 34 00:02:04,005 --> 00:02:09,005 so we could have written Mark higher BMI right here, 35 35 00:02:09,330 --> 00:02:11,280 but as I said in the previous lecture 36 36 00:02:11,280 --> 00:02:12,620 it's actually more common 37 37 00:02:12,620 --> 00:02:14,963 to write the condition directly in here. 38 38 00:02:15,890 --> 00:02:18,972 Let's get rid of this variable here, 39 39 00:02:18,972 --> 00:02:22,740 and then let's come here and get this string 40 40 00:02:24,595 --> 00:02:28,900 that we want to then log to the console. 41 41 00:02:28,900 --> 00:02:30,333 So console.log, 42 42 00:02:32,010 --> 00:02:34,970 and so this makes sense, right? 43 43 00:02:34,970 --> 00:02:38,020 If BMIMark is greater than BMIJohn, 44 44 00:02:38,020 --> 00:02:41,993 then we log to the console Mark's BMI is higher than John's, 45 45 00:02:43,430 --> 00:02:47,100 and if not, then we use the else statement. 46 46 00:02:47,100 --> 00:02:48,350 Let's copy this one here. 47 47 00:02:54,203 --> 00:02:58,120 In this case, John's BMI is higher than Mark's, 48 48 00:02:59,410 --> 00:03:01,020 and actually let's log both of them 49 49 00:03:01,020 --> 00:03:04,033 to the console here first, 50 50 00:03:05,105 --> 00:03:09,363 just so we see if our if/else statement 51 51 00:03:09,363 --> 00:03:10,970 is working as expected. 52 52 00:03:10,970 --> 00:03:12,543 So BMIMark and BMIJohn. 53 53 00:03:15,690 --> 00:03:19,203 As you see here, the VS code autocompletion is pretty smart. 54 54 00:03:21,050 --> 00:03:23,633 Give it a safe, let's try that, 55 55 00:03:25,670 --> 00:03:29,740 and we see John's BMI is higher than Mark's. 56 56 00:03:29,740 --> 00:03:32,020 So this one is Mark's, this one is John's, 57 57 00:03:32,020 --> 00:03:35,470 and indeed John's BMI is higher. 58 58 00:03:35,470 --> 00:03:40,470 Basically this condition here turned out to be false 59 59 00:03:40,492 --> 00:03:43,243 and the else block was executed. 60 60 00:03:44,330 --> 00:03:49,330 Let's try the same now with this first set of data here, 61 61 00:03:49,440 --> 00:03:52,920 and I'm commenting them out again using command slash 62 62 00:03:52,920 --> 00:03:55,283 or control slash on Windows. 63 63 00:03:56,290 --> 00:03:58,053 I need to comment out this one, 64 64 00:03:59,640 --> 00:04:01,760 okay, give it a safe, 65 65 00:04:01,760 --> 00:04:04,060 and now we should see the opposite. 66 66 00:04:04,060 --> 00:04:07,573 Indeed, now Mark's BMI is higher than John's. 67 67 00:04:09,332 --> 00:04:11,183 That is part one, 68 68 00:04:13,195 --> 00:04:18,195 and now part two is to actually write a template string, 69 69 00:04:19,240 --> 00:04:21,923 or this would be called a template literal. 70 70 00:04:22,880 --> 00:04:23,993 We just fix that. 71 71 00:04:25,130 --> 00:04:26,950 We should use a template literal 72 72 00:04:26,950 --> 00:04:29,690 to include the actual BMI values, 73 73 00:04:29,690 --> 00:04:32,023 so like this here between parenthesis. 74 74 00:04:33,200 --> 00:04:34,483 So, let's do that. 75 75 00:04:35,863 --> 00:04:38,887 We're going to transform this to backticks. 76 76 00:04:44,040 --> 00:04:46,020 That's the first thing, 77 77 00:04:46,020 --> 00:04:50,280 and then let's see the template again. 78 78 00:04:50,280 --> 00:04:54,140 Okay, so after the BMI we include two parenthesis 79 79 00:04:54,140 --> 00:04:55,830 and then in the parenthesis 80 80 00:04:55,830 --> 00:04:57,573 is where we want the actual value. 81 81 00:04:58,409 --> 00:05:01,930 This is where we put essentially the placeholder. 82 82 00:05:01,930 --> 00:05:04,000 Here we will put BMIMark 83 83 00:05:12,393 --> 00:05:13,810 and here BMIJohn. 84 84 00:05:18,220 --> 00:05:21,163 Now let's just copy this to make it a bit faster. 85 85 00:05:24,390 --> 00:05:26,663 Mark, and down here, John. 86 86 00:05:33,220 --> 00:05:36,017 Okay, let's see. 87 87 00:05:37,758 --> 00:05:40,893 Yeah, that works just fine. 88 88 00:05:42,010 --> 00:05:45,060 Cool, so with this we solved the challenge, 89 89 00:05:45,060 --> 00:05:47,770 and again, if you did it in a slightly different way, 90 90 00:05:47,770 --> 00:05:49,000 don't worry at all. 91 91 00:05:49,000 --> 00:05:52,080 That's completely normal and it's actually a good thing. 92 92 00:05:52,080 --> 00:05:54,120 It means that you're basically finding 93 93 00:05:54,120 --> 00:05:58,500 your own style of coding, which is a really a good thing 94 94 00:05:58,500 --> 00:06:00,480 so don't worry about that. 95 95 00:06:00,480 --> 00:06:04,410 What matters is that you actually used an if/else statement. 96 96 00:06:04,410 --> 00:06:06,400 That was, of course, mandatory. 97 97 00:06:06,400 --> 00:06:10,170 Otherwise you couldn't have made this work at all. 98 98 00:06:10,170 --> 00:06:12,667 All right, so this was a lot of fun 99 99 00:06:12,667 --> 00:06:16,980 because we actually made our code do something now. 100 100 00:06:16,980 --> 00:06:19,523 I hope you can really feel that as well. 8509

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