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
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
1 1
Welcome to the second coding challenge. 2
2
In this one you're gonna test your knowledge 3
3
of the if/else statement that we just learned about. 4
4
This coding challenge number two 5
5
will basically improve the first challenge. 6
6
We're still gonna be using DBMI example, 7
7
but we are going to print a nice output to the console 8
8
and this output is gonna tell us who has the higher BMI. 9
9
The output message can be either 10
10
Mark's BMI is higher than John's 11
11
or John's BMI is higher than Mark's. 12
12
That's the first part, 13
13
and then as a second part use a template string 14
14
to include the actual BMI values in the outputs. 15
15
Okay, and as you can guess, 16
16
you should probably use an if/else statement 17
17
to complete this challenge, right? 18
18
So, pause the video now and I'll see you in a second. 19
19
All right. 20
20
Again, I hope that you managed to do this. 21
21
Let me show you how I did it. 22
22
Let's start by getting this code from the other challenge, 23
23
so coding challenge number one, 24
24
because of course we don't have to repeat the same code. 25
25
Here we have the mass and the height of both John and Mark, 26
26
and we already have their BMIs calculated. 27
27
We also have this condition here basically already, 28
28
so this operation here already tells us 29
29
whether Mark has a higher BMI or not, right? 30
30
Let's get rid of this 31
31
and let's write our if/else statement. 32
32
If BMIMark is greater than BMIJohn, 33
33
and here we could have just used this variable, 34
34
so we could have written Mark higher BMI right here, 35
35
but as I said in the previous lecture 36
36
it's actually more common 37
37
to write the condition directly in here. 38
38
Let's get rid of this variable here, 39
39
and then let's come here and get this string 40
40
that we want to then log to the console. 41
41
So console.log, 42
42
and so this makes sense, right? 43
43
If BMIMark is greater than BMIJohn, 44
44
then we log to the console Mark's BMI is higher than John's, 45
45
and if not, then we use the else statement. 46
46
Let's copy this one here. 47
47
In this case, John's BMI is higher than Mark's, 48
48
and actually let's log both of them 49
49
to the console here first, 50
50
just so we see if our if/else statement 51
51
is working as expected. 52
52
So BMIMark and BMIJohn. 53
53
As you see here, the VS code autocompletion is pretty smart. 54
54
Give it a safe, let's try that, 55
55
and we see John's BMI is higher than Mark's. 56
56
So this one is Mark's, this one is John's, 57
57
and indeed John's BMI is higher. 58
58
Basically this condition here turned out to be false 59
59
and the else block was executed. 60
60
Let's try the same now with this first set of data here, 61
61
and I'm commenting them out again using command slash 62
62
or control slash on Windows. 63
63
I need to comment out this one, 64
64
okay, give it a safe, 65
65
and now we should see the opposite. 66
66
Indeed, now Mark's BMI is higher than John's. 67
67
That is part one, 68
68
and now part two is to actually write a template string, 69
69
or this would be called a template literal. 70
70
We just fix that. 71
71
We should use a template literal 72
72
to include the actual BMI values, 73
73
so like this here between parenthesis. 74
74
So, let's do that. 75
75
We're going to transform this to backticks. 76
76
That's the first thing, 77
77
and then let's see the template again. 78
78
Okay, so after the BMI we include two parenthesis 79
79
and then in the parenthesis 80
80
is where we want the actual value. 81
81
This is where we put essentially the placeholder. 82
82
Here we will put BMIMark 83
83
and here BMIJohn. 84
84
Now let's just copy this to make it a bit faster. 85
85
Mark, and down here, John. 86
86
Okay, let's see. 87
87
Yeah, that works just fine. 88
88
Cool, so with this we solved the challenge, 89
89
and again, if you did it in a slightly different way, 90
90
don't worry at all. 91
91
That's completely normal and it's actually a good thing. 92
92
It means that you're basically finding 93
93
your own style of coding, which is a really a good thing 94
94
so don't worry about that. 95
95
What matters is that you actually used an if/else statement. 96
96
That was, of course, mandatory. 97
97
Otherwise you couldn't have made this work at all. 98
98
All right, so this was a lot of fun 99
99
because we actually made our code do something now. 100
100
I hope you can really feel that as well.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.