All language subtitles for 016 Coding Challenge 1.en_US

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
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
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
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
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
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-PT Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
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:01,070 --> 00:00:02,480 It's now finally time 2 00:00:02,480 --> 00:00:05,130 for your very first coding challenge. 3 00:00:05,130 --> 00:00:08,970 So coding challenges are basically coding exercises 4 00:00:08,970 --> 00:00:11,170 that you have to code on your own, 5 00:00:11,170 --> 00:00:13,700 and they are super important for you to test 6 00:00:13,700 --> 00:00:15,820 and reinforce all the skills 7 00:00:15,820 --> 00:00:17,680 that you just learned before. 8 00:00:17,680 --> 00:00:20,610 That's why there are dozens of coding challenges 9 00:00:20,610 --> 00:00:24,560 in this course, because students love them and they are one 10 00:00:24,560 --> 00:00:26,883 of the best ways of learning. 11 00:00:28,420 --> 00:00:31,070 And so this is the coding challenge number one 12 00:00:31,070 --> 00:00:33,790 of the section or coding exercise 13 00:00:33,790 --> 00:00:36,640 if you prefer to call it that. 14 00:00:36,640 --> 00:00:39,150 Now all of these coding challenges are also 15 00:00:39,150 --> 00:00:40,760 in a separate PDF file 16 00:00:40,760 --> 00:00:42,540 that is available somewhere 17 00:00:42,540 --> 00:00:43,700 in the course. 18 00:00:43,700 --> 00:00:46,300 So you can also get this text from there. 19 00:00:46,300 --> 00:00:49,030 You don't have to read the video. 20 00:00:49,030 --> 00:00:53,130 Okay. Now, anyway, the exercise is this 21 00:00:53,130 --> 00:00:54,760 Mark and John are trying 22 00:00:54,760 --> 00:00:59,070 to compare their body mass indexes and the BMI 23 00:00:59,070 --> 00:01:02,200 is calculated using this formula. 24 00:01:02,200 --> 00:01:07,200 So BMI is equal to mass divided by the height squared. 25 00:01:07,490 --> 00:01:08,709 Okay. 26 00:01:08,709 --> 00:01:11,690 And so squared is the exponentiation operator that we talked 27 00:01:11,690 --> 00:01:14,410 about before with the two. 28 00:01:14,410 --> 00:01:15,243 Okay. 29 00:01:15,243 --> 00:01:16,730 And so that is also the same 30 00:01:16,730 --> 00:01:20,880 to mass equals height times height. 31 00:01:20,880 --> 00:01:21,713 Okay. 32 00:01:21,713 --> 00:01:25,560 So this part is the same as this one. 33 00:01:25,560 --> 00:01:26,393 So you can choose 34 00:01:26,393 --> 00:01:29,140 to calculate the BMI either way. 35 00:01:29,140 --> 00:01:31,730 Now, what matters is that a mass needs to be 36 00:01:31,730 --> 00:01:35,490 in kilograms and to height needs to be in meters. 37 00:01:35,490 --> 00:01:36,920 So it's not gonna work 38 00:01:36,920 --> 00:01:40,710 with the U.S measures like feet and pound, 39 00:01:40,710 --> 00:01:43,560 but that's why I have the test data here already 40 00:01:43,560 --> 00:01:46,220 with the correct measurements. 41 00:01:46,220 --> 00:01:49,540 Anyway, here is what I want you to do for this challenge. 42 00:01:49,540 --> 00:01:52,850 One, you should store mark's and John's mass 43 00:01:52,850 --> 00:01:54,840 and height in variables, 44 00:01:54,840 --> 00:01:57,780 and you should do this for test data one. 45 00:01:57,780 --> 00:01:59,500 So this data here 46 00:01:59,500 --> 00:02:03,500 and then also for test data two, all right, 47 00:02:03,500 --> 00:02:06,830 then using these variables calculate both 48 00:02:06,830 --> 00:02:10,350 their BMI's using the formula that I just showed you. 49 00:02:10,350 --> 00:02:12,470 And again, you can use either one, 50 00:02:12,470 --> 00:02:14,530 it's gonna work the same way. 51 00:02:14,530 --> 00:02:17,510 Of course, to then check these values if they make sense, 52 00:02:17,510 --> 00:02:18,980 you can log them to the console, 53 00:02:18,980 --> 00:02:22,100 just like we have been doing up until this point. 54 00:02:22,100 --> 00:02:23,730 Then finally, I want you 55 00:02:23,730 --> 00:02:27,197 to create a Boolean variable called 'markHigherBMI', 56 00:02:28,510 --> 00:02:30,300 which will contain the information, 57 00:02:30,300 --> 00:02:33,760 whether Mark has a higher BMI than John. 58 00:02:33,760 --> 00:02:34,593 Okay. 59 00:02:34,593 --> 00:02:36,450 And this is actually similar to something 60 00:02:36,450 --> 00:02:38,520 that we did before So I hope that 61 00:02:38,520 --> 00:02:41,340 you can make this one work just fine. 62 00:02:41,340 --> 00:02:45,700 So now please really try to solve this problem on your own. 63 00:02:45,700 --> 00:02:47,470 And remember the advice that I gave you 64 00:02:47,470 --> 00:02:48,770 in the beginning. 65 00:02:48,770 --> 00:02:51,950 Don't try to make this perfect for now. 66 00:02:51,950 --> 00:02:54,670 What matters is really just to make it work. 67 00:02:54,670 --> 00:02:56,700 It doesn't matter if you write clean code 68 00:02:56,700 --> 00:02:59,720 or perfect code or efficient code, 69 00:02:59,720 --> 00:03:01,370 just make it work for now. 70 00:03:01,370 --> 00:03:02,500 All right. 71 00:03:02,500 --> 00:03:04,980 So pause the video now And I see you 72 00:03:04,980 --> 00:03:07,113 in a second with the solution. 73 00:03:08,310 --> 00:03:09,143 All right. 74 00:03:10,072 --> 00:03:12,510 I hope you manage to complete all the three Points 75 00:03:12,510 --> 00:03:14,280 of this challenge. 76 00:03:14,280 --> 00:03:15,113 And so here is 77 00:03:15,113 --> 00:03:17,163 how I would have implemented it. 78 00:03:18,860 --> 00:03:22,480 So I'm starting with number one, of course. 79 00:03:22,480 --> 00:03:26,237 And so let's say const massMark equals 78. 80 00:03:32,030 --> 00:03:32,863 Okay. 81 00:03:32,863 --> 00:03:34,040 So that's just, 82 00:03:34,040 --> 00:03:34,983 what is written here. 83 00:03:36,160 --> 00:03:41,160 And then heightMark equals one 69 84 00:03:45,840 --> 00:03:48,270 and then the same for John. 85 00:03:48,270 --> 00:03:52,360 So massJohn equals 92 86 00:03:53,870 --> 00:03:58,870 and then heightJohn equals one 95 now, right? 87 00:04:01,880 --> 00:04:04,110 And if you used different variable names, 88 00:04:04,110 --> 00:04:06,040 that's not a problem at all. 89 00:04:06,040 --> 00:04:08,220 As long as they are nicely descriptive, 90 00:04:08,220 --> 00:04:09,740 like these ones here, 91 00:04:09,740 --> 00:04:10,960 you're going to be fine. 92 00:04:10,960 --> 00:04:14,840 Also, you might've used a let here instead of const, 93 00:04:14,840 --> 00:04:17,160 because you might assume that these are values that 94 00:04:17,160 --> 00:04:19,560 are susceptible to change, 95 00:04:19,560 --> 00:04:22,290 especially here the mass, all right. 96 00:04:22,290 --> 00:04:26,380 However, I still decided to use const because I already know 97 00:04:26,380 --> 00:04:28,840 that I'm not going to change these values here 98 00:04:28,840 --> 00:04:30,620 throughout the program. 99 00:04:30,620 --> 00:04:32,550 And so just as we learned before, 100 00:04:32,550 --> 00:04:35,810 I prefer to always use const by default 101 00:04:35,810 --> 00:04:37,220 and I advise you 102 00:04:37,220 --> 00:04:38,473 to actually do the same. 103 00:04:39,610 --> 00:04:40,690 Okay. 104 00:04:40,690 --> 00:04:44,820 Anyway, let's now calculate the actual BMIs. 105 00:04:44,820 --> 00:04:46,873 So const BMIMark 106 00:04:46,873 --> 00:04:51,740 equals massMark divided, 107 00:04:56,370 --> 00:04:58,680 and let's check out the formula again, 108 00:04:58,680 --> 00:05:01,550 divided by the height squared. 109 00:05:01,550 --> 00:05:04,623 So that's going to be heightMark squared 110 00:05:09,760 --> 00:05:13,737 and then the BMIJohn So that's massJohn, 111 00:05:17,470 --> 00:05:20,860 and this time let's actually use the other formula. 112 00:05:20,860 --> 00:05:22,553 So this one here. 113 00:05:23,890 --> 00:05:27,970 So we're gonna use, heightJohn times heightJohn again. 114 00:05:32,650 --> 00:05:33,670 Okay. 115 00:05:33,670 --> 00:05:36,300 And now let's log both of them 116 00:05:36,300 --> 00:05:37,483 to the console here. 117 00:05:38,400 --> 00:05:39,740 So BMIMark and BMIJohn. 118 00:05:47,730 --> 00:05:50,030 And now we have an error here. 119 00:05:50,030 --> 00:05:52,563 Oh, of course I missed the dot log. 120 00:05:54,140 --> 00:05:55,280 Okay. 121 00:05:55,280 --> 00:05:56,800 Try it again. 122 00:05:56,800 --> 00:05:58,383 And here we go. 123 00:05:59,795 --> 00:06:01,820 So we see that BMIMark is higher 124 00:06:03,440 --> 00:06:05,148 than John's BMI. 125 00:06:05,148 --> 00:06:06,720 Okay. 126 00:06:06,720 --> 00:06:07,553 So I hope you got the same numbers here 127 00:06:07,553 --> 00:06:08,760 than I did. 128 00:06:08,760 --> 00:06:10,470 And if not, 129 00:06:10,470 --> 00:06:11,780 I guess you should probably check 130 00:06:11,780 --> 00:06:14,840 your code unless I have some mistake here. 131 00:06:14,840 --> 00:06:16,313 Let me check that actually. 132 00:06:17,400 --> 00:06:20,150 But I think everything is good. 133 00:06:20,150 --> 00:06:20,983 Okay. 134 00:06:20,983 --> 00:06:21,990 So if something is wrong, 135 00:06:21,990 --> 00:06:23,950 then please just let me know. 136 00:06:23,950 --> 00:06:25,040 All right. 137 00:06:25,040 --> 00:06:26,650 Now, if you implemented this 138 00:06:26,650 --> 00:06:28,850 in a different way, for example, 139 00:06:28,850 --> 00:06:30,760 you might not have created 140 00:06:30,760 --> 00:06:33,420 these separate variables here, 141 00:06:33,420 --> 00:06:35,730 then that's not a problem at all. 142 00:06:35,730 --> 00:06:36,563 Okay. 143 00:06:36,563 --> 00:06:38,690 You could have logged these calculations straight 144 00:06:38,690 --> 00:06:39,650 to the console. 145 00:06:39,650 --> 00:06:41,380 No problem at all. 146 00:06:41,380 --> 00:06:44,800 Again, what matters here is that you make this work and 147 00:06:44,800 --> 00:06:45,920 that in the end you get 148 00:06:45,920 --> 00:06:47,633 these same results here. 149 00:06:49,440 --> 00:06:52,852 Anyway, let's now also do step three 150 00:06:52,852 --> 00:06:56,117 and create a variable called 'markHigherBMI'. 151 00:06:57,212 --> 00:06:59,597 So let's just grab this here and const. 152 00:07:03,970 --> 00:07:05,580 And so what we're trying to figure out 153 00:07:05,580 --> 00:07:10,580 is if the BMI of Mark is higher than the BMI of John, right? 154 00:07:16,010 --> 00:07:19,280 And so that's what comparison operators are for, 155 00:07:19,280 --> 00:07:23,670 because remember that this one here will return either true 156 00:07:23,670 --> 00:07:25,390 or false. 157 00:07:25,390 --> 00:07:26,470 In our example, 158 00:07:26,470 --> 00:07:31,140 if BMI Mark is larger than one of John, 159 00:07:31,140 --> 00:07:33,530 then the result of this 160 00:07:33,530 --> 00:07:35,980 whole operator here will be true 161 00:07:35,980 --> 00:07:38,230 and otherwise it's gonna be false. 162 00:07:38,230 --> 00:07:39,063 Okay. 163 00:07:39,063 --> 00:07:40,800 So that's exactly what we did before 164 00:07:40,800 --> 00:07:44,940 in this example with the ages 165 00:07:44,940 --> 00:07:46,970 if I remember correctly. 166 00:07:46,970 --> 00:07:51,810 So where's that? It's right here. 167 00:07:51,810 --> 00:07:55,010 In this case, it was 'isFullAge' variable. 168 00:07:55,010 --> 00:07:55,843 Right? 169 00:07:57,100 --> 00:07:58,290 Okay. 170 00:07:58,290 --> 00:08:01,593 Anyway, let's log to your tutor console as well. 171 00:08:02,940 --> 00:08:04,290 And so we expect this one 172 00:08:04,290 --> 00:08:07,060 to be true, right? 173 00:08:07,060 --> 00:08:11,910 Because Mark's BMI is 27 and John's is 24. 174 00:08:11,910 --> 00:08:15,510 And so Mark's is larger and so the result 175 00:08:15,510 --> 00:08:17,460 of this should be true. 176 00:08:17,460 --> 00:08:20,670 So let's check that and indeed, 177 00:08:20,670 --> 00:08:21,823 we get true. 178 00:08:22,680 --> 00:08:23,580 Nice. 179 00:08:23,580 --> 00:08:26,510 So we basically solved it. 180 00:08:26,510 --> 00:08:29,930 Now I just want to do the same here for test data too. 181 00:08:29,930 --> 00:08:31,223 So we'll just copy this. 182 00:08:32,190 --> 00:08:35,630 So copy, and then I will simply comment 183 00:08:35,630 --> 00:08:37,893 out these first ones. 184 00:08:39,890 --> 00:08:43,693 So now I'm replacing these with 95, 185 00:08:44,628 --> 00:08:48,310 one 88 and then here for John, 186 00:08:48,310 --> 00:08:52,723 we have 85 and one 76. 187 00:08:53,790 --> 00:08:54,960 And the rest of course 188 00:08:55,878 --> 00:08:56,988 is the same. 189 00:08:56,988 --> 00:08:58,660 And that's the beauty of using variables 190 00:08:58,660 --> 00:09:01,140 because now all we have to do is to change 191 00:09:01,140 --> 00:09:03,100 these values in one place 192 00:09:03,100 --> 00:09:06,010 and then the changes will be propagated to the rest 193 00:09:06,010 --> 00:09:08,010 of the code here, 194 00:09:08,010 --> 00:09:10,703 which references these variables. 195 00:09:12,640 --> 00:09:13,473 Cool. 196 00:09:13,473 --> 00:09:15,050 So let's reload. 197 00:09:15,050 --> 00:09:20,050 And now BMI of John is 27. 198 00:09:20,800 --> 00:09:24,810 So it's a larger than 26.8. 199 00:09:24,810 --> 00:09:28,318 It's actually very close, but still, 200 00:09:28,318 --> 00:09:30,850 BMIMark is now lower 201 00:09:30,850 --> 00:09:32,180 than BMIJohn. 202 00:09:32,180 --> 00:09:34,880 So here we asked the question basically 203 00:09:34,880 --> 00:09:36,840 is BMIMark a larger 204 00:09:36,840 --> 00:09:38,470 than BMIJohn? 205 00:09:38,470 --> 00:09:40,230 And in this case it's not. 206 00:09:40,230 --> 00:09:41,480 So it's false. 207 00:09:41,480 --> 00:09:43,320 And so that's exactly the result 208 00:09:43,320 --> 00:09:44,970 that we get here. 209 00:09:44,970 --> 00:09:45,920 All right? 210 00:09:45,920 --> 00:09:50,530 So this one is solved and I hope you solved it as well. 211 00:09:50,530 --> 00:09:52,620 Again, it does not matter at all, 212 00:09:52,620 --> 00:09:54,770 if you did it in a different way, 213 00:09:54,770 --> 00:09:57,170 as long as the results were the same. 214 00:09:57,170 --> 00:10:01,630 So basically as long as you actually made it work. 215 00:10:01,630 --> 00:10:04,650 So, hopefully that was a lot of fun 216 00:10:04,650 --> 00:10:07,350 and you could practice your skillset little bit, 217 00:10:07,350 --> 00:10:09,490 which is really something essential 218 00:10:09,490 --> 00:10:11,980 to learn programming properly, 219 00:10:11,980 --> 00:10:15,010 without repetition and reinforcing your knowledge 220 00:10:15,010 --> 00:10:18,620 It's impossible, really to learn how to code. 221 00:10:18,620 --> 00:10:21,010 Anyway, see you now in the next video 222 00:10:21,010 --> 00:10:24,404 where we're going to continue learning the fundamentals 223 00:10:24,404 --> 00:10:26,254 of the beautiful JavaScript language. 14844

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