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
French
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
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
1 1
It's now finally time 2
2
for your very first coding challenge. 3
3
So coding challenges are basically coding exercises 4
4
that you have to code on your own, 5
5
and they are super important for you to test 6
6
and reinforce all the skills 7
7
that you just learned before. 8
8
That's why there are dozens of coding challenges 9
9
in this course, because students love them and they are one 10
10
of the best ways of learning. 11
11
And so this is the coding challenge number one 12
12
of the section or coding exercise 13
13
if you prefer to call it that. 14
14
Now all of these coding challenges are also 15
15
in a separate PDF file 16
16
that is available somewhere 17
17
in the course. 18
18
So you can also get this text from there. 19
19
You don't have to read the video. 20
20
Okay. Now, anyway, the exercise is this 21
21
Mark and John are trying 22
22
to compare their body mass indexes and the BMI 23
23
is calculated using this formula. 24
24
So BMI is equal to mass divided by the height squared. 25
25
Okay. 26
26
And so squared is the exponentiation operator that we talked 27
27
about before with the two. 28
28
Okay. 29
29
And so that is also the same 30
30
to mass equals height times height. 31
31
Okay. 32
32
So this part is the same as this one. 33
33
So you can choose 34
34
to calculate the BMI either way. 35
35
Now, what matters is that a mass needs to be 36
36
in kilograms and to height needs to be in meters. 37
37
So it's not gonna work 38
38
with the U.S measures like feet and pound, 39
39
but that's why I have the test data here already 40
40
with the correct measurements. 41
41
Anyway, here is what I want you to do for this challenge. 42
42
One, you should store mark's and John's mass 43
43
and height in variables, 44
44
and you should do this for test data one. 45
45
So this data here 46
46
and then also for test data two, all right, 47
47
then using these variables calculate both 48
48
their BMI's using the formula that I just showed you. 49
49
And again, you can use either one, 50
50
it's gonna work the same way. 51
51
Of course, to then check these values if they make sense, 52
52
you can log them to the console, 53
53
just like we have been doing up until this point. 54
54
Then finally, I want you 55
55
to create a Boolean variable called 'markHigherBMI', 56
56
which will contain the information, 57
57
whether Mark has a higher BMI than John. 58
58
Okay. 59
59
And this is actually similar to something 60
60
that we did before So I hope that 61
61
you can make this one work just fine. 62
62
So now please really try to solve this problem on your own. 63
63
And remember the advice that I gave you 64
64
in the beginning. 65
65
Don't try to make this perfect for now. 66
66
What matters is really just to make it work. 67
67
It doesn't matter if you write clean code 68
68
or perfect code or efficient code, 69
69
just make it work for now. 70
70
All right. 71
71
So pause the video now And I see you 72
72
in a second with the solution. 73
73
All right. 74
74
I hope you manage to complete all the three Points 75
75
of this challenge. 76
76
And so here is 77
77
how I would have implemented it. 78
78
So I'm starting with number one, of course. 79
79
And so let's say const massMark equals 78. 80
80
Okay. 81
81
So that's just, 82
82
what is written here. 83
83
And then heightMark equals one 69 84
84
and then the same for John. 85
85
So massJohn equals 92 86
86
and then heightJohn equals one 95 now, right? 87
87
And if you used different variable names, 88
88
that's not a problem at all. 89
89
As long as they are nicely descriptive, 90
90
like these ones here, 91
91
you're going to be fine. 92
92
Also, you might've used a let here instead of const, 93
93
because you might assume that these are values that 94
94
are susceptible to change, 95
95
especially here the mass, all right. 96
96
However, I still decided to use const because I already know 97
97
that I'm not going to change these values here 98
98
throughout the program. 99
99
And so just as we learned before, 100
100
I prefer to always use const by default 101
101
and I advise you 102
102
to actually do the same. 103
103
Okay. 104
104
Anyway, let's now calculate the actual BMIs. 105
105
So const BMIMark 106
106
equals massMark divided, 107
107
and let's check out the formula again, 108
108
divided by the height squared. 109
109
So that's going to be heightMark squared 110
110
and then the BMIJohn So that's massJohn, 111
111
and this time let's actually use the other formula. 112
112
So this one here. 113
113
So we're gonna use, heightJohn times heightJohn again. 114
114
Okay. 115
115
And now let's log both of them 116
116
to the console here. 117
117
So BMIMark and BMIJohn. 118
118
And now we have an error here. 119
119
Oh, of course I missed the dot log. 120
120
Okay. 121
121
Try it again. 122
122
And here we go. 123
123
So we see that BMIMark is higher 124
124
than John's BMI. 125
125
Okay. 126
126
So I hope you got the same numbers here 127
127
than I did. 128
128
And if not, 129
129
I guess you should probably check 130
130
your code unless I have some mistake here. 131
131
Let me check that actually. 132
132
But I think everything is good. 133
133
Okay. 134
134
So if something is wrong, 135
135
then please just let me know. 136
136
All right. 137
137
Now, if you implemented this 138
138
in a different way, for example, 139
139
you might not have created 140
140
these separate variables here, 141
141
then that's not a problem at all. 142
142
Okay. 143
143
You could have logged these calculations straight 144
144
to the console. 145
145
No problem at all. 146
146
Again, what matters here is that you make this work and 147
147
that in the end you get 148
148
these same results here. 149
149
Anyway, let's now also do step three 150
150
and create a variable called 'markHigherBMI'. 151
151
So let's just grab this here and const. 152
152
And so what we're trying to figure out 153
153
is if the BMI of Mark is higher than the BMI of John, right? 154
154
And so that's what comparison operators are for, 155
155
because remember that this one here will return either true 156
156
or false. 157
157
In our example, 158
158
if BMI Mark is larger than one of John, 159
159
then the result of this 160
160
whole operator here will be true 161
161
and otherwise it's gonna be false. 162
162
Okay. 163
163
So that's exactly what we did before 164
164
in this example with the ages 165
165
if I remember correctly. 166
166
So where's that? It's right here. 167
167
In this case, it was 'isFullAge' variable. 168
168
Right? 169
169
Okay. 170
170
Anyway, let's log to your tutor console as well. 171
171
And so we expect this one 172
172
to be true, right? 173
173
Because Mark's BMI is 27 and John's is 24. 174
174
And so Mark's is larger and so the result 175
175
of this should be true. 176
176
So let's check that and indeed, 177
177
we get true. 178
178
Nice. 179
179
So we basically solved it. 180
180
Now I just want to do the same here for test data too. 181
181
So we'll just copy this. 182
182
So copy, and then I will simply comment 183
183
out these first ones. 184
184
So now I'm replacing these with 95, 185
185
one 88 and then here for John, 186
186
we have 85 and one 76. 187
187
And the rest of course 188
188
is the same. 189
189
And that's the beauty of using variables 190
190
because now all we have to do is to change 191
191
these values in one place 192
192
and then the changes will be propagated to the rest 193
193
of the code here, 194
194
which references these variables. 195
195
Cool. 196
196
So let's reload. 197
197
And now BMI of John is 27. 198
198
So it's a larger than 26.8. 199
199
It's actually very close, but still, 200
200
BMIMark is now lower 201
201
than BMIJohn. 202
202
So here we asked the question basically 203
203
is BMIMark a larger 204
204
than BMIJohn? 205
205
And in this case it's not. 206
206
So it's false. 207
207
And so that's exactly the result 208
208
that we get here. 209
209
All right? 210
210
So this one is solved and I hope you solved it as well. 211
211
Again, it does not matter at all, 212
212
if you did it in a different way, 213
213
as long as the results were the same. 214
214
So basically as long as you actually made it work. 215
215
So, hopefully that was a lot of fun 216
216
and you could practice your skillset little bit, 217
217
which is really something essential 218
218
to learn programming properly, 219
219
without repetition and reinforcing your knowledge 220
220
It's impossible, really to learn how to code. 221
221
Anyway, see you now in the next video 222
222
where we're going to continue learning the fundamentals 223
223
of the beautiful JavaScript language.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.