1
00:00:00,660 --> 00:00:04,170
Again, I hope that you managed to do this.

2
00:00:04,170 --> 00:00:08,730
So let me show you how I did it.

3
00:00:08,730 --> 00:00:10,920
So let's start by getting this code

4
00:00:10,920 --> 00:00:12,900
from the other challenge.

5
00:00:12,900 --> 00:00:15,120
So coding challenge number 1,

6
00:00:15,120 --> 00:00:19,833
because, of course, we don't have to repeat the same code.

7
00:00:23,070 --> 00:00:25,500
So here we have the mass and the height

8
00:00:25,500 --> 00:00:28,530
of both John and Mark,

9
00:00:28,530 --> 00:00:32,100
and we already have their BMIs calculated.

10
00:00:32,100 --> 00:00:37,100
We also have this condition here, basically, already.

11
00:00:37,140 --> 00:00:38,996
So this operation here already tells us

12
00:00:38,996 --> 00:00:42,843
whether Mark has a higher BMI or not, right?

13
00:00:43,710 --> 00:00:46,323
So let's get rid of this,

14
00:00:47,310 --> 00:00:50,043
and so let's write our if/else statement.

15
00:00:51,060 --> 00:00:56,060
So if BMIMark is greater than BMIJohn,

16
00:00:58,320 --> 00:01:03,320
and here we could have just used this variable, right?

17
00:01:03,390 --> 00:01:07,650
So we could have written markHigherBMI right here,

18
00:01:07,650 --> 00:01:09,600
but as I said in the previous lecture,

19
00:01:09,600 --> 00:01:10,950
it's actually more common

20
00:01:10,950 --> 00:01:13,980
to write the condition directly in here.

21
00:01:13,980 --> 00:01:17,130
So let's get rid of this variable here,

22
00:01:17,130 --> 00:01:21,070
and then let's come here and get this string

23
00:01:23,550 --> 00:01:27,240
that we want to then log to the console.

24
00:01:27,240 --> 00:01:28,653
So console.log.

25
00:01:30,360 --> 00:01:33,090
And so this makes sense, right?

26
00:01:33,090 --> 00:01:36,330
So if BMIMark is greater than BMIJohn,

27
00:01:36,330 --> 00:01:38,047
then we log to the console,

28
00:01:38,047 --> 00:01:40,407
"Mark's BMI is higher than John's!"

29
00:01:41,580 --> 00:01:45,090
and if not, then we use the else statement.

30
00:01:45,090 --> 00:01:46,593
So let's copy this one here.

31
00:01:52,260 --> 00:01:56,607
So in this case, "John's BMI is higher than Mark's!"

32
00:01:57,750 --> 00:01:59,340
And actually, let's log both of them

33
00:01:59,340 --> 00:02:02,373
to the console here first,

34
00:02:04,020 --> 00:02:06,840
just so we see if our if/else statement

35
00:02:06,840 --> 00:02:09,300
is working as expected.

36
00:02:09,300 --> 00:02:12,933
So BMIMark and BMIJohn.

37
00:02:13,890 --> 00:02:14,723
And as you see here,

38
00:02:14,723 --> 00:02:17,523
the VSCode autocompletion is pretty smart.

39
00:02:19,380 --> 00:02:21,963
Give it a save. Let's try it out.

40
00:02:24,000 --> 00:02:28,050
And we see "John's BMI is higher than Mark's!"

41
00:02:28,050 --> 00:02:30,330
So this one is Mark's, this one is John's,

42
00:02:30,330 --> 00:02:33,270
and indeed, John's BMI is higher.

43
00:02:33,270 --> 00:02:36,430
And so basically, this condition here

44
00:02:37,410 --> 00:02:39,240
turned out to be false,

45
00:02:39,240 --> 00:02:41,583
and the else block was executed.

46
00:02:42,480 --> 00:02:47,480
So let's try the same now with this first set of data here.

47
00:02:47,760 --> 00:02:51,270
And I'm commenting them out, again, using command slash,

48
00:02:51,270 --> 00:02:53,613
or control slash on Windows.

49
00:02:54,450 --> 00:02:56,373
So I need to comment out this one.

50
00:02:57,990 --> 00:03:02,370
Okay, give it a save, and now we should see the opposite.

51
00:03:02,370 --> 00:03:05,913
And indeed, now Mark's BMI is higher than John's.

52
00:03:07,500 --> 00:03:11,073
So that is part 1, right?

53
00:03:12,360 --> 00:03:17,360
And now part 2 is to actually write a template string,

54
00:03:17,580 --> 00:03:20,253
or this would be called a template literal.

55
00:03:21,210 --> 00:03:22,353
We just fix that.

56
00:03:23,220 --> 00:03:25,260
So we should use a template literal

57
00:03:25,260 --> 00:03:28,020
to include the actual BMI values,

58
00:03:28,020 --> 00:03:30,333
so like this here, between parentheses.

59
00:03:31,530 --> 00:03:32,823
So let's do that,

60
00:03:34,050 --> 00:03:37,173
and so we're gonna transform this to backticks.

61
00:03:42,030 --> 00:03:44,340
So that's the first thing,

62
00:03:44,340 --> 00:03:48,600
and then let's see the template again.

63
00:03:48,600 --> 00:03:52,470
Okay, so after the BMI, we included parentheses,

64
00:03:52,470 --> 00:03:54,180
and then in the parentheses

65
00:03:54,180 --> 00:03:56,460
is where we want the actual value.

66
00:03:56,460 --> 00:04:00,090
And so this is where we put essentially the placeholder.

67
00:04:00,090 --> 00:04:02,403
So here, we will put BMIMark,

68
00:04:10,437 --> 00:04:12,520
and here, BMIJohn, right?

69
00:04:16,560 --> 00:04:19,503
And now let's just copy this to make it a bit faster.

70
00:04:22,710 --> 00:04:24,983
Mark, and then here, John.

71
00:04:31,560 --> 00:04:32,393
Okay.

72
00:04:33,540 --> 00:04:35,040
Let's see.

73
00:04:35,040 --> 00:04:39,243
And yeah, that works just fine.

74
00:04:40,320 --> 00:04:43,380
Cool. So with this, we solved the challenge.

75
00:04:43,380 --> 00:04:46,080
And again, if you did it in a slightly different way,

76
00:04:46,080 --> 00:04:47,310
don't worry at all.

77
00:04:47,310 --> 00:04:50,430
That's completely normal, and it's actually a good thing.

78
00:04:50,430 --> 00:04:52,440
It means that you're basically finding

79
00:04:52,440 --> 00:04:56,820
your own style of coding, which is really a good thing,

80
00:04:56,820 --> 00:04:58,830
so don't worry about that.

81
00:04:58,830 --> 00:05:02,760
What matters is that you actually used an if/else statement.

82
00:05:02,760 --> 00:05:04,710
That was, of course, mandatory.

83
00:05:04,710 --> 00:05:08,490
Otherwise, you couldn't have made this work at all.

84
00:05:08,490 --> 00:05:09,323
All right?

85
00:05:09,323 --> 00:05:11,340
So this was a lot of fun,

86
00:05:11,340 --> 00:05:15,300
because we actually made our code do something now.

87
00:05:15,300 --> 00:05:17,853
I hope you can really feel that as well.

