WEBVTT

1
00:00:00.480 --> 00:00:01.620
<v Jonas>Okay, hopefully,</v>

2
00:00:01.620 --> 00:00:06.620
you managed to complete at least point 1 and point 2.

3
00:00:06.630 --> 00:00:09.840
And so let's start by solving these two.

4
00:00:09.840 --> 00:00:14.760
So number one is calculating the average of both teams.

5
00:00:14.760 --> 00:00:17.673
So let's create one variable for each.

6
00:00:19.647 --> 00:00:23.400
So scoreDolphins, and so to calculate the average,

7
00:00:23.400 --> 00:00:25.620
we simply add up all the three scores

8
00:00:25.620 --> 00:00:27.480
and then divide it by a three.

9
00:00:27.480 --> 00:00:29.763
So we already did something similar before.

10
00:00:30.690 --> 00:00:35.690
So that's 96 + 108 + 89,

11
00:00:37.170 --> 00:00:39.330
and then divide it by 3.

12
00:00:39.330 --> 00:00:41.010
And we need these parenthesis

13
00:00:41.010 --> 00:00:44.760
so that these plus operations are executed first,

14
00:00:44.760 --> 00:00:47.910
because the grouping, so the parenthesis,

15
00:00:47.910 --> 00:00:49.593
have a higher precedence.

16
00:00:50.460 --> 00:00:55.460
Okay, scoreKoalas is 88 + 91 + 110,

17
00:01:00.540 --> 00:01:02.313
and again, divide it by 3.

18
00:01:03.840 --> 00:01:07.833
And now let's quickly log both to the console here,

19
00:01:09.150 --> 00:01:12.063
scoreDolphins and scoreKoalas.

20
00:01:17.568 --> 00:01:19.500
Okay, so they're pretty close,

21
00:01:19.500 --> 00:01:23.670
but the dolphins have a little bit higher of an average.

22
00:01:23.670 --> 00:01:27.420
And so that's what we're working on in point 2,

23
00:01:27.420 --> 00:01:31.500
where we're gonna compare the average of both teams.

24
00:01:31.500 --> 00:01:36.420
So we are gonna use an 'if' statement

25
00:01:37.290 --> 00:01:38.793
or 'if else' probably.

26
00:01:39.840 --> 00:01:43.773
So scoreDolphins, if it's greater than scoreKoalas,

27
00:01:48.000 --> 00:01:52.180
then log to the console 'Dolphins win the trophy.'

28
00:01:56.610 --> 00:01:59.193
And we can get fancy here with some emoji.

29
00:02:01.500 --> 00:02:03.150
Let's see if we got one up,

30
00:02:03.150 --> 00:02:05.220
that's the one I'm looking for.

31
00:02:05.220 --> 00:02:07.020
But of course, once more,

32
00:02:07.020 --> 00:02:09.873
you don't need to worry about this part.

33
00:02:10.740 --> 00:02:12.753
Let's just copy this for the next one.

34
00:02:13.770 --> 00:02:15.660
So 'else,' and actually,

35
00:02:15.660 --> 00:02:19.290
we're going to use an 'else if' because of the draw,

36
00:02:19.290 --> 00:02:21.453
but let's talk about that one later.

37
00:02:22.860 --> 00:02:27.860
So if the score of the koalas is greater than scoreDolphins,

38
00:02:28.440 --> 00:02:31.080
then we're gonna print the opposite

39
00:02:31.080 --> 00:02:34.113
so that koalas win the trophy.

40
00:02:34.980 --> 00:02:37.137
And finally, 'else if,'

41
00:02:39.076 --> 00:02:42.653
scoreDolphins is equal to scoreKoalas,

42
00:02:44.040 --> 00:02:49.040
then we can simply say that no one wins the trophy,

43
00:02:52.050 --> 00:02:57.003
or actually, both win the trophy.

44
00:02:59.970 --> 00:03:02.910
Okay, so let's test that.

45
00:03:02.910 --> 00:03:06.210
And indeed, we get that the dolphins win the trophy,

46
00:03:06.210 --> 00:03:10.590
and that's because, as we know, this value is greater.

47
00:03:10.590 --> 00:03:12.300
And so actually, this first condition here

48
00:03:12.300 --> 00:03:14.400
turns out to be true right away.

49
00:03:14.400 --> 00:03:17.283
And so this block of code here gets executed.

50
00:03:18.150 --> 00:03:19.770
Now, let's just quickly increase

51
00:03:19.770 --> 00:03:22.200
the score of the koalas here,

52
00:03:22.200 --> 00:03:27.200
let's say 100, just to see if the second part also works.

53
00:03:29.280 --> 00:03:32.850
And indeed, now the koalas win the trophy.

54
00:03:32.850 --> 00:03:34.623
Okay, but let's put it back here.

55
00:03:35.520 --> 00:03:40.230
And here you could have actually done it in another way.

56
00:03:40.230 --> 00:03:45.230
So you could have done scoreDolphins less than scoreKoalas.

57
00:03:45.930 --> 00:03:47.730
So, basically, write the same as here,

58
00:03:47.730 --> 00:03:51.660
but instead of the greater, you would've used the less than.

59
00:03:51.660 --> 00:03:53.340
So that's the exact same thing,

60
00:03:53.340 --> 00:03:56.280
and both are equally valid.

61
00:03:56.280 --> 00:03:57.930
Then here in the last part,

62
00:03:57.930 --> 00:04:01.350
actually, we wouldn't even have needed this part,

63
00:04:01.350 --> 00:04:05.010
so that the score of dolphins is equal to score of koalas,

64
00:04:05.010 --> 00:04:08.040
because that's actually the only scenario that's left

65
00:04:08.040 --> 00:04:10.263
given these previous two conditions.

66
00:04:11.160 --> 00:04:14.070
So basically, if none of these here were true,

67
00:04:14.070 --> 00:04:15.660
really the only thing possible

68
00:04:15.660 --> 00:04:17.580
would be that they had the same score.

69
00:04:17.580 --> 00:04:21.630
And so a simple 'else' block would've been enough here.

70
00:04:21.630 --> 00:04:24.300
But anyway, this works just fine too.

71
00:04:24.300 --> 00:04:28.470
And so, again, what matters is that you made it work

72
00:04:28.470 --> 00:04:30.720
even if you did some things differently.

73
00:04:30.720 --> 00:04:33.000
For example, you could have stored the conditions

74
00:04:33.000 --> 00:04:35.310
in separate bullion variables,

75
00:04:35.310 --> 00:04:38.280
or you could have structured the 'if else' statement

76
00:04:38.280 --> 00:04:39.720
in some different way.

77
00:04:39.720 --> 00:04:42.090
But if you got the same result that we just saw here,

78
00:04:42.090 --> 00:04:43.680
then congratulations,

79
00:04:43.680 --> 00:04:46.743
that's a great work, well done, really.

80
00:04:48.439 --> 00:04:52.500
So maybe you even made it to Bonus number 1 and 2.

81
00:04:52.500 --> 00:04:56.100
And so let me solve them here now as well.

82
00:04:56.100 --> 00:04:59.613
So let's start by calculating the average.

83
00:05:05.280 --> 00:05:07.383
So this is gonna be Bonus 1,

84
00:05:09.067 --> 00:05:12.063
and yeah, let's copy this one too,

85
00:05:13.410 --> 00:05:16.500
let's copy this one, let's copy this one,

86
00:05:16.500 --> 00:05:18.750
so should have done it all in one go,

87
00:05:18.750 --> 00:05:21.933
so that we can now comment out this first part.

88
00:05:24.947 --> 00:05:28.980
So for test number 1, this should be 97.

89
00:05:28.980 --> 00:05:33.007
Then the second one should be 112 and 101.

90
00:05:35.010 --> 00:05:36.780
And for the koalas,

91
00:05:36.780 --> 00:05:41.463
we have 109, 95, and 123.

92
00:05:47.040 --> 00:05:48.990
Let's just quickly test.

93
00:05:48.990 --> 00:05:51.870
And so right now, the koalas win the trophy.

94
00:05:51.870 --> 00:05:54.060
So for now, everything works the same,

95
00:05:54.060 --> 00:05:57.870
but now we need to include this important condition here,

96
00:05:57.870 --> 00:06:00.270
which is that, with this rule,

97
00:06:00.270 --> 00:06:02.670
a team only wins if it has a higher score

98
00:06:02.670 --> 00:06:05.070
than the other team, which we already have,

99
00:06:05.070 --> 00:06:08.763
and at the same time, a score of at least 100 points.

100
00:06:10.140 --> 00:06:12.273
Okay, easy enough.

101
00:06:13.560 --> 00:06:17.670
So in this case, the dolphins win, okay?

102
00:06:17.670 --> 00:06:19.710
But now we also need to ensure

103
00:06:19.710 --> 00:06:23.040
that the dolphins have a score higher or equal 100.

104
00:06:23.040 --> 00:06:24.543
So let's just say that.

105
00:06:26.520 --> 00:06:29.730
So dolphins need to have a higher score than koalas,

106
00:06:29.730 --> 00:06:34.730
and scoreDolphins need to be greater or equal 100,

107
00:06:36.720 --> 00:06:40.770
and that's it, that's all we need for this requirement.

108
00:06:40.770 --> 00:06:43.140
And then the same thing here.

109
00:06:43.140 --> 00:06:46.170
So this is the scenario where the koalas win.

110
00:06:46.170 --> 00:06:47.760
So for the koalas to win,

111
00:06:47.760 --> 00:06:50.790
they need to have a higher score than the dolphins,

112
00:06:50.790 --> 00:06:55.790
and at the same time, they need to have at least 100 points,

113
00:06:56.160 --> 00:07:00.930
so just like before, greater or equal 100.

114
00:07:00.930 --> 00:07:03.990
And so once more, we used a logical operator here

115
00:07:03.990 --> 00:07:07.253
to model this situation essentially, okay?

116
00:07:09.390 --> 00:07:11.100
And actually, I think, with this,

117
00:07:11.100 --> 00:07:15.363
we implemented this bonus number 1.

118
00:07:17.334 --> 00:07:19.080
So let's try that again.

119
00:07:19.080 --> 00:07:21.080
And right now, of course, it still works

120
00:07:21.960 --> 00:07:25.740
because both have a score higher than 100.

121
00:07:25.740 --> 00:07:27.600
But let's change that now here,

122
00:07:27.600 --> 00:07:32.600
according to test data 2, to 106, so 106,

123
00:07:36.960 --> 00:07:39.660
and now they both win the trophy.

124
00:07:39.660 --> 00:07:44.660
So let's actually decrease all of these points by 20.

125
00:07:45.900 --> 00:07:50.283
So let's make it 81 and 86.

126
00:07:51.210 --> 00:07:55.140
So the average should still be the same now, yeah,

127
00:07:55.140 --> 00:07:57.420
but they're both below 100 now.

128
00:07:57.420 --> 00:08:01.140
And so this brings us to bonus number 2

129
00:08:01.140 --> 00:08:02.700
that says that the minimum score

130
00:08:02.700 --> 00:08:05.040
should also apply to a draw.

131
00:08:05.040 --> 00:08:09.420
So a draw only happens when both teams have the same score

132
00:08:09.420 --> 00:08:14.160
and both a score greater or equal 100 points, okay?

133
00:08:14.160 --> 00:08:16.470
And otherwise, no team wins the trophy,

134
00:08:16.470 --> 00:08:17.670
so that's important too.

135
00:08:19.320 --> 00:08:21.990
So let's translate that.

136
00:08:21.990 --> 00:08:24.600
So to be a draw, the score needs to be the same,

137
00:08:24.600 --> 00:08:26.010
which we already have,

138
00:08:26.010 --> 00:08:31.010
and the score of dolphins

139
00:08:31.080 --> 00:08:33.753
needs to be greater or equal 100,

140
00:08:34.620 --> 00:08:39.000
and the score of koalas

141
00:08:39.000 --> 00:08:42.953
needs to be greater, equal 100, okay?

142
00:08:45.502 --> 00:08:50.502
And else, well, then we can say that no one wins the trophy.

143
00:08:58.590 --> 00:09:03.590
And let's just add some sad emoji here. (chuckling)

144
00:09:05.838 --> 00:09:08.550
Okay, let's try that.

145
00:09:08.550 --> 00:09:13.110
And now we get that no one wins the trophy, okay?

146
00:09:13.110 --> 00:09:17.520
So that's because their scores are now below 100.

147
00:09:17.520 --> 00:09:21.600
And so we actually enter this last case here.

148
00:09:21.600 --> 00:09:24.660
But if we go back to the averages that we had before,

149
00:09:24.660 --> 00:09:29.660
so 106 and 101, let's see,

150
00:09:30.840 --> 00:09:32.790
and now both win the trophy

151
00:09:32.790 --> 00:09:35.310
because they have the same amount of points

152
00:09:35.310 --> 00:09:39.780
and they both have a number of points above 100.

153
00:09:39.780 --> 00:09:42.120
And so that's exactly what we have here.

154
00:09:42.120 --> 00:09:47.120
So same points, dolphins have over or at least 100 points

155
00:09:47.880 --> 00:09:50.700
and koalas have at least 100 points.

156
00:09:50.700 --> 00:09:53.253
And so in this case, both win the trophy.

157
00:09:54.960 --> 00:09:57.010
Finally, let's also test the scenario

158
00:09:58.080 --> 00:10:00.480
in which both have below,

159
00:10:00.480 --> 00:10:03.720
but the dolphins have a little bit more.

160
00:10:03.720 --> 00:10:05.283
Let's put this one here at 80.

161
00:10:06.330 --> 00:10:11.330
And so, now we see that the dolphins have 96 points

162
00:10:11.700 --> 00:10:15.330
and the koalas have 84, but still, no one wins the trophy.

163
00:10:15.330 --> 00:10:19.980
And that's because the dolphins have more than the koalas.

164
00:10:19.980 --> 00:10:22.650
So this part of the requirement is true,

165
00:10:22.650 --> 00:10:25.890
but they do not have over 100.

166
00:10:25.890 --> 00:10:28.620
So this part here is false, okay?

167
00:10:28.620 --> 00:10:32.250
And so true, this first part here is true,

168
00:10:32.250 --> 00:10:33.600
and the second part is false,

169
00:10:33.600 --> 00:10:36.180
and true and false gives false.

170
00:10:36.180 --> 00:10:38.730
And so then, all of these are skipped

171
00:10:38.730 --> 00:10:41.073
because they're also, obviously, false.

172
00:10:42.999 --> 00:10:45.990
And so we go straight to this last block,

173
00:10:45.990 --> 00:10:47.610
and so no one wins the trophy,

174
00:10:47.610 --> 00:10:50.610
which is exactly what we were expecting

175
00:10:50.610 --> 00:10:53.310
as a result here, okay?

176
00:10:53.310 --> 00:10:55.260
Now, if you didn't manage to do this here,

177
00:10:55.260 --> 00:10:57.480
again, don't worry, because I know

178
00:10:57.480 --> 00:10:59.700
that this is a little bit complicated already.

179
00:10:59.700 --> 00:11:01.830
And so, in case you managed

180
00:11:01.830 --> 00:11:04.350
to successfully complete this challenge,

181
00:11:04.350 --> 00:11:08.580
then a huge congratulations to you, well done.

182
00:11:08.580 --> 00:11:10.200
But if, for some reason,

183
00:11:10.200 --> 00:11:12.750
you were not able to complete the challenge,

184
00:11:12.750 --> 00:11:15.690
then don't worry all too much about it.

185
00:11:15.690 --> 00:11:18.030
You can always go back to the lectures

186
00:11:18.030 --> 00:11:20.940
where we first learned about these topics.

187
00:11:20.940 --> 00:11:23.580
And you can, of course, after this video,

188
00:11:23.580 --> 00:11:26.280
also review the code a little bit more carefully

189
00:11:26.280 --> 00:11:29.610
to make sure 100% that you understand,

190
00:11:29.610 --> 00:11:34.260
especially this last example that we just worked on, okay?

191
00:11:34.260 --> 00:11:37.560
But anyway, great job in completing this challenge,

192
00:11:37.560 --> 00:11:40.323
and now I see you in the next video.

