1
00:00:01,270 --> 00:00:02,690
<v Lecturer>I hope you're excited</v>

2
00:00:02,690 --> 00:00:04,680
for your next coding challenge

3
00:00:04,680 --> 00:00:06,673
so let's jump right in.

4
00:00:08,400 --> 00:00:11,400
And this time we have a different coding challenge.

5
00:00:11,400 --> 00:00:14,610
So, this time we have two gymnastics teams

6
00:00:14,610 --> 00:00:17,430
called the Dolphins and the Koalas.

7
00:00:17,430 --> 00:00:20,560
And they compete against each other three times,

8
00:00:20,560 --> 00:00:22,960
then the team with the highest ever score

9
00:00:22,960 --> 00:00:25,820
is the winner and wins a trophy.

10
00:00:25,820 --> 00:00:28,400
So here are your tasks.

11
00:00:28,400 --> 00:00:31,730
First, you should calculate the average score

12
00:00:31,730 --> 00:00:35,170
for each of the teams using the test data below.

13
00:00:35,170 --> 00:00:38,950
So, this test data right here, okay.

14
00:00:38,950 --> 00:00:41,930
Then compare the teams' average scores

15
00:00:41,930 --> 00:00:44,690
to determine the winner of the competition

16
00:00:44,690 --> 00:00:47,270
and also print it to the console.

17
00:00:47,270 --> 00:00:49,810
Now there might be a draw between the teams

18
00:00:49,810 --> 00:00:53,090
which means that they have the same average score.

19
00:00:53,090 --> 00:00:57,050
So, you need to test for that situation as well.

20
00:00:57,050 --> 00:00:58,860
So this is the basic challenge

21
00:00:58,860 --> 00:01:02,300
and I think this will be great to test the knowledge

22
00:01:02,300 --> 00:01:05,060
that you gained over the last couple of videos.

23
00:01:05,060 --> 00:01:07,360
Now if you want to take it to the next level

24
00:01:07,360 --> 00:01:09,360
and make it a little more difficult,

25
00:01:09,360 --> 00:01:13,460
you can try out the bonus one and bonus two.

26
00:01:13,460 --> 00:01:16,033
So, let's take a look at this.

27
00:01:17,070 --> 00:01:20,130
So, bonus one is to include the requirement

28
00:01:20,130 --> 00:01:22,960
for a minimum score of 100.

29
00:01:22,960 --> 00:01:25,870
So what this means is that the team only wins

30
00:01:25,870 --> 00:01:28,720
if it has a higher score than the other team.

31
00:01:28,720 --> 00:01:32,950
And, at the same time a score of at least 100 points.

32
00:01:32,950 --> 00:01:35,170
And to help you solve this one,

33
00:01:35,170 --> 00:01:38,180
I'm giving you the hint of using a logical operator

34
00:01:38,180 --> 00:01:41,770
to test for the minimum score of 100 points.

35
00:01:41,770 --> 00:01:45,370
Also, you will also probably need multiple else if blocks.

36
00:01:45,370 --> 00:01:46,650
All right.

37
00:01:46,650 --> 00:01:48,930
Now the second bonus here,

38
00:01:48,930 --> 00:01:52,340
is that the minimum score also applies to a draw.

39
00:01:52,340 --> 00:01:56,090
So a draw only happens when both teams have the same score

40
00:01:56,090 --> 00:02:00,300
and both have a score greater or equal 100 points.

41
00:02:00,300 --> 00:02:04,620
And otherwise no team at all wins the trophy, all right.

42
00:02:04,620 --> 00:02:08,700
And then here you actually have the test data for bonus one

43
00:02:08,700 --> 00:02:10,540
and for bonus two.

44
00:02:10,540 --> 00:02:12,730
And you can of course play around with these scores

45
00:02:12,730 --> 00:02:16,390
and change them to match all the different scenarios, okay.

46
00:02:16,390 --> 00:02:18,163
So these are not static,

47
00:02:19,189 --> 00:02:21,170
they're just some initial values that make sense

48
00:02:21,170 --> 00:02:23,653
but from there feel free to change them.

49
00:02:24,740 --> 00:02:26,730
So the first two are the easier ones

50
00:02:26,730 --> 00:02:29,810
and for these you use this test data.

51
00:02:29,810 --> 00:02:32,120
Then to make it a bit more difficult

52
00:02:32,120 --> 00:02:35,360
you can do bonus two and bonus one

53
00:02:35,360 --> 00:02:39,700
and for that you use these two test data sets, all right?

54
00:02:39,700 --> 00:02:43,580
Now if one of the bonuses turns out to be too hard for you

55
00:02:43,580 --> 00:02:45,120
then just don't do it.

56
00:02:45,120 --> 00:02:47,330
It's perfectly fine, okay.

57
00:02:47,330 --> 00:02:50,620
What matters is that you don't become frustrated.

58
00:02:50,620 --> 00:02:53,180
The goal here is really just to test the stuff

59
00:02:53,180 --> 00:02:54,510
that we did before

60
00:02:54,510 --> 00:02:57,980
and absolutely not to get you frustrated

61
00:02:57,980 --> 00:03:01,920
and thinking that coding might not be for you, okay.

62
00:03:01,920 --> 00:03:04,650
And again, don't focus on writing efficient

63
00:03:04,650 --> 00:03:07,410
or optimized code at this point,

64
00:03:07,410 --> 00:03:09,640
all we want here is to learn programming

65
00:03:09,640 --> 00:03:11,290
and to learn JavaScript.

66
00:03:11,290 --> 00:03:14,470
So, just make it work and, yeah...

67
00:03:14,470 --> 00:03:17,800
That's it for instructions about this challenge.

68
00:03:17,800 --> 00:03:21,083
So, pause the video now and I see you in a second.

69
00:03:24,400 --> 00:03:28,150
Now okay, hopefully you managed to complete

70
00:03:28,150 --> 00:03:30,900
at least point one and point two

71
00:03:30,900 --> 00:03:34,100
and so let's start by solving these two.

72
00:03:34,100 --> 00:03:39,030
So, number one is calculating the average of both teams.

73
00:03:39,030 --> 00:03:41,923
So let's create one variable for each.

74
00:03:43,060 --> 00:03:45,533
So, score Dolphins

75
00:03:45,533 --> 00:03:47,660
and so to calculate the average

76
00:03:47,660 --> 00:03:49,900
we simply add up all the three scores

77
00:03:49,900 --> 00:03:51,730
and then divide it by 3.

78
00:03:51,730 --> 00:03:53,940
So we already did something similar before

79
00:03:54,940 --> 00:03:59,023
so that's 96 plus 108 plus 89,

80
00:04:01,450 --> 00:04:03,570
and then divided by three.

81
00:04:03,570 --> 00:04:05,280
And we need these parentheses

82
00:04:05,280 --> 00:04:09,040
so that these plus operations are executed first.

83
00:04:09,040 --> 00:04:10,240
Because the grouping...

84
00:04:10,240 --> 00:04:13,853
So the parentheses have a higher precedence.

85
00:04:14,710 --> 00:04:19,710
Okay, score Koalas is 88 plus 91 plus 110

86
00:04:24,800 --> 00:04:26,510
And again divided by 3

87
00:04:28,130 --> 00:04:32,600
And now let's quickly log both to the console here.

88
00:04:32,600 --> 00:04:37,223
Score Dolphins and score Koalas.

89
00:04:41,350 --> 00:04:43,780
Okay, so they're pretty close

90
00:04:43,780 --> 00:04:47,950
but the Dolphins have a little bit higher of an average.

91
00:04:47,950 --> 00:04:51,700
And so that's what we're working on in point two

92
00:04:51,700 --> 00:04:55,780
where we're going to compare the average of both teams.

93
00:04:55,780 --> 00:05:00,780
So, we're gonna use an if statement or if else probably.

94
00:05:04,110 --> 00:05:08,553
So score dolphins, if it's greater than score Koalas

95
00:05:12,480 --> 00:05:14,263
then log to the console,

96
00:05:16,940 --> 00:05:20,880
Dolphins win the trophy.

97
00:05:20,880 --> 00:05:23,273
And we can get fancy here with some emoji.

98
00:05:25,790 --> 00:05:27,300
Let's see if we got one.

99
00:05:27,300 --> 00:05:29,500
Ah! That's the one I'm looking for.

100
00:05:29,500 --> 00:05:31,280
But of course once more,

101
00:05:31,280 --> 00:05:34,133
you don't need to worry about this part.

102
00:05:35,010 --> 00:05:37,033
Let's just copy this for the next one.

103
00:05:38,040 --> 00:05:39,500
So, else...

104
00:05:39,500 --> 00:05:42,120
And actually we are going to use an else if

105
00:05:42,120 --> 00:05:43,540
because of the draw.

106
00:05:43,540 --> 00:05:45,713
But let's talk about that one later.

107
00:05:47,130 --> 00:05:49,250
So, if the score of the Koalas

108
00:05:49,250 --> 00:05:52,730
is greater than score Dolphins

109
00:05:52,730 --> 00:05:55,360
then we're gonna print the opposite,

110
00:05:55,360 --> 00:05:58,393
so that Koalas win the trophy.

111
00:05:59,240 --> 00:06:04,240
And finally, else if score Dolphins is equal to score Koalas

112
00:06:07,975 --> 00:06:12,975
then we can simply say that no one wins the trophy,

113
00:06:16,320 --> 00:06:21,293
or actually both win the trophy.

114
00:06:24,240 --> 00:06:28,070
Okay, so let's test that and indeed,

115
00:06:28,070 --> 00:06:30,470
we get that Dolphins win the trophy

116
00:06:30,470 --> 00:06:34,850
and that because as we know, this value is greater.

117
00:06:34,850 --> 00:06:36,590
And so actually this first condition here

118
00:06:36,590 --> 00:06:38,660
turns out to be true right away

119
00:06:38,660 --> 00:06:41,543
and so this block of code here gets executed.

120
00:06:42,410 --> 00:06:44,110
Now let's just quickly increase

121
00:06:44,110 --> 00:06:46,490
the score of the Koalas here.

122
00:06:46,490 --> 00:06:51,490
Let's say 100, just to see if the second part also works

123
00:06:53,530 --> 00:06:56,283
And it did, now the Koalas win the trophy.

124
00:06:57,120 --> 00:06:58,820
Okay, but let's put it back here

125
00:06:59,770 --> 00:07:04,490
and here you could have actually done it in another way.

126
00:07:04,490 --> 00:07:07,310
So you could have done score Dolphins

127
00:07:07,310 --> 00:07:10,180
less than score Koalas.

128
00:07:10,180 --> 00:07:12,000
So basically you write the same as here

129
00:07:12,000 --> 00:07:13,860
but instead of the greater,

130
00:07:13,860 --> 00:07:15,920
you will have used the less than.

131
00:07:15,920 --> 00:07:20,550
So that's the exact same thing and both are equally valid.

132
00:07:20,550 --> 00:07:22,200
Then here in the last part

133
00:07:22,200 --> 00:07:25,620
actually, we wouldn't even have needed this part

134
00:07:25,620 --> 00:07:29,300
so that the score of Dolphins is equal to score of Koalas,

135
00:07:29,300 --> 00:07:32,320
because that's actually the only scenario that's left

136
00:07:32,320 --> 00:07:34,513
given these previous two conditions.

137
00:07:35,430 --> 00:07:38,300
So, basically if none of these here were true,

138
00:07:38,300 --> 00:07:39,940
really the only thing possible

139
00:07:39,940 --> 00:07:41,850
would be that they had the same score

140
00:07:41,850 --> 00:07:45,890
and so simple else block would have been enough here.

141
00:07:45,890 --> 00:07:48,590
But anyway, this works just fine too

142
00:07:48,590 --> 00:07:52,740
and so, again what matters is that you made it work

143
00:07:52,740 --> 00:07:54,990
even if you did some things differently.

144
00:07:54,990 --> 00:07:55,823
For example,

145
00:07:55,823 --> 00:07:57,260
you could have stored the conditions

146
00:07:57,260 --> 00:07:59,570
in separate boolean variables

147
00:07:59,570 --> 00:08:02,145
or you could have structured the if else statement

148
00:08:02,145 --> 00:08:03,980
in some different way.

149
00:08:03,980 --> 00:08:06,380
But if you got the same result that we just saw here,

150
00:08:06,380 --> 00:08:07,920
then congratulations.

151
00:08:07,920 --> 00:08:09,800
That's a great work.

152
00:08:09,800 --> 00:08:11,003
Well done, really.

153
00:08:11,910 --> 00:08:16,760
So, maybe you even made it to bonus number one and two

154
00:08:16,760 --> 00:08:20,370
and so let me solve them here now, as well.

155
00:08:20,370 --> 00:08:23,903
So, let's start by calculating the average.

156
00:08:29,570 --> 00:08:32,360
So, this is gonna be bonus one.

157
00:08:32,360 --> 00:08:36,333
And yeah, let's copy this one, too.

158
00:08:37,670 --> 00:08:38,960
Let's copy this one.

159
00:08:38,960 --> 00:08:40,770
Let's copy this one.

160
00:08:40,770 --> 00:08:43,040
So we should have done it all in one go

161
00:08:43,040 --> 00:08:46,203
so that we can now command out this first part.

162
00:08:48,400 --> 00:08:51,040
So, for test number one,

163
00:08:51,040 --> 00:08:53,450
this should be 97,

164
00:08:53,450 --> 00:08:57,193
then the second one should be 112 and 101

165
00:08:59,290 --> 00:09:03,833
And for the Koalas, we have 109, 95 and 123.

166
00:09:11,390 --> 00:09:13,220
Let's just quickly test.

167
00:09:13,220 --> 00:09:16,150
And so right now the Koalas win the trophy.

168
00:09:16,150 --> 00:09:18,320
So for now everything works the same

169
00:09:18,320 --> 00:09:22,130
but now we need to include this important condition here,

170
00:09:22,130 --> 00:09:24,201
which is that with this rule,

171
00:09:24,201 --> 00:09:26,930
a team only wins if it has a higher score

172
00:09:26,930 --> 00:09:29,350
than the other team, which we already have.

173
00:09:29,350 --> 00:09:33,033
And, at the same time a score of at least 100 points.

174
00:09:34,410 --> 00:09:35,550
Okay.

175
00:09:35,550 --> 00:09:36,553
Easy enough.

176
00:09:37,820 --> 00:09:40,693
So in this case, the Dolphins win.

177
00:09:41,620 --> 00:09:44,000
But now we also need to ensure

178
00:09:44,000 --> 00:09:47,300
that the Dolphins have a score higher or equal 100.

179
00:09:47,300 --> 00:09:48,793
So let's just say that.

180
00:09:50,800 --> 00:09:53,990
So Dolphins need to have a higher score than Koalas

181
00:09:53,990 --> 00:09:58,990
and score Dolphins needs to be greater or equal 100

182
00:10:01,000 --> 00:10:02,100
and that's it.

183
00:10:02,100 --> 00:10:05,030
That's all we need for this requirement.

184
00:10:05,030 --> 00:10:07,420
And then the same thing here.

185
00:10:07,420 --> 00:10:10,440
So this is the scenario where the Koalas win.

186
00:10:10,440 --> 00:10:12,020
So for the Koalas to win

187
00:10:12,020 --> 00:10:14,467
they need to have a higher score than the Dolphins

188
00:10:14,467 --> 00:10:16,459
and at the same time,

189
00:10:16,459 --> 00:10:20,420
they need to have at least 100 points.

190
00:10:20,420 --> 00:10:24,373
So just like before, greater or equal 100.

191
00:10:25,230 --> 00:10:27,775
And so once more, we used a logical operator here

192
00:10:27,775 --> 00:10:31,003
to model this situation essentially.

193
00:10:33,130 --> 00:10:36,570
Okay, and actually with this we implemented

194
00:10:37,719 --> 00:10:40,410
this bonus number one.

195
00:10:40,410 --> 00:10:43,340
So let's try that again

196
00:10:43,340 --> 00:10:45,277
and right now of course it still works

197
00:10:45,277 --> 00:10:50,000
because both have a score higher than 100

198
00:10:50,000 --> 00:10:51,535
but let's change that now here

199
00:10:51,535 --> 00:10:54,853
according to test data two, to 106.

200
00:10:55,840 --> 00:10:59,190
So, 106...

201
00:11:01,210 --> 00:11:03,930
and now they both win the trophy.

202
00:11:03,930 --> 00:11:08,190
So let's actually decrease all these points

203
00:11:08,190 --> 00:11:10,180
like by 20.

204
00:11:10,180 --> 00:11:14,563
So let's make it 81 and 86,

205
00:11:15,470 --> 00:11:18,560
so the average should still be the same now

206
00:11:18,560 --> 00:11:21,690
Yeah, but they're both below 100 now.

207
00:11:21,690 --> 00:11:25,032
And so this brings us to our bonus number two

208
00:11:25,032 --> 00:11:26,950
that says that the minimum score

209
00:11:26,950 --> 00:11:29,310
should also apply to a draw.

210
00:11:29,310 --> 00:11:33,670
So a draw only happens when both teams have the same score

211
00:11:33,670 --> 00:11:38,450
and both score greater or equal 100 points, okay.

212
00:11:38,450 --> 00:11:40,750
And otherwise, no team wins the trophy.

213
00:11:40,750 --> 00:11:41,950
So that's important too.

214
00:11:43,570 --> 00:11:46,270
So let's translate that.

215
00:11:46,270 --> 00:11:48,870
So to be a draw, the score needs to be the same

216
00:11:48,870 --> 00:11:50,270
which we already have.

217
00:11:50,270 --> 00:11:54,737
And the score of Dolphins

218
00:11:54,737 --> 00:11:57,950
needs to be greater or equal 100

219
00:11:58,870 --> 00:12:03,870
and the score of Koalas needs to be greater, equal 100, okay

220
00:12:08,950 --> 00:12:11,900
And else...

221
00:12:11,900 --> 00:12:15,403
Well, then we can say that no one wins the trophy.

222
00:12:23,016 --> 00:12:26,766
And let's just add some sad emoji here, okay.

223
00:12:31,530 --> 00:12:32,820
Let's try that

224
00:12:32,820 --> 00:12:37,400
and now we get that no one wins the trophy, okay.

225
00:12:37,400 --> 00:12:41,800
So that's because their scores are now below 100.

226
00:12:41,800 --> 00:12:45,870
And so, we actually enter this last case here.

227
00:12:45,870 --> 00:12:48,930
But if we go back to the averages that we had before

228
00:12:48,930 --> 00:12:53,930
so 106 and 101, let's see.

229
00:12:55,190 --> 00:12:57,050
Now both win the trophy

230
00:12:57,050 --> 00:12:59,600
because they have the same amount of points

231
00:12:59,600 --> 00:13:04,040
and they both have a number of points above 100.

232
00:13:04,040 --> 00:13:06,380
And so that's exactly what we have here.

233
00:13:06,380 --> 00:13:08,240
So, same points,

234
00:13:08,240 --> 00:13:12,140
Dolphins have over, or at least 100 points

235
00:13:12,140 --> 00:13:14,970
and Koalas have at least 100 points.

236
00:13:14,970 --> 00:13:17,483
And so in this case, both win the trophy.

237
00:13:18,520 --> 00:13:21,461
Finally, let's also test the scenario

238
00:13:21,461 --> 00:13:24,750
in which both have below

239
00:13:24,750 --> 00:13:28,000
but the Dolphins have a little bit more.

240
00:13:28,000 --> 00:13:32,220
Let's put this one here at 80, and so,

241
00:13:32,220 --> 00:13:36,000
now we see that the Dolphins have 96 points

242
00:13:36,000 --> 00:13:37,550
and the Koalas have 84

243
00:13:37,550 --> 00:13:39,570
but still no one wins the trophy.

244
00:13:39,570 --> 00:13:43,857
And that's because the Dolphins have more than the Koalas

245
00:13:43,857 --> 00:13:46,930
so this part of the requirement is true

246
00:13:46,930 --> 00:13:50,150
but they do not have over 100

247
00:13:50,150 --> 00:13:52,900
so this part here is false, okay

248
00:13:52,900 --> 00:13:56,520
and so true, this first part here is true

249
00:13:56,520 --> 00:13:57,970
and the second part is false.

250
00:13:57,970 --> 00:14:00,450
True and false gives false

251
00:14:00,450 --> 00:14:03,010
and so then all of these are skipped

252
00:14:03,010 --> 00:14:05,260
because they are also obviously false

253
00:14:06,170 --> 00:14:10,270
and so we go straight to this last block.

254
00:14:10,270 --> 00:14:11,870
And so no one wins the trophy

255
00:14:11,870 --> 00:14:14,435
which is exactly what we were expecting

256
00:14:14,435 --> 00:14:17,570
as a result here, okay.

257
00:14:17,570 --> 00:14:19,530
Now if you didn't manage to do this here,

258
00:14:19,530 --> 00:14:22,200
again, don't worry because I know that this is

259
00:14:22,200 --> 00:14:24,010
a little bit complicated already

260
00:14:24,010 --> 00:14:27,050
and so in case you managed to successfully

261
00:14:27,050 --> 00:14:31,430
complete this challenge, then a huge congratulations to you.

262
00:14:31,430 --> 00:14:32,830
Well done.

263
00:14:32,830 --> 00:14:34,440
But if for some reason,

264
00:14:34,440 --> 00:14:37,040
you were not able to complete the challenge

265
00:14:37,040 --> 00:14:39,950
then don't worry all too much about it.

266
00:14:39,950 --> 00:14:42,270
You can always go back to the lectures

267
00:14:42,270 --> 00:14:44,806
where we first learned about these topics

268
00:14:44,806 --> 00:14:47,860
and you can of course, after this video

269
00:14:47,860 --> 00:14:50,540
also review the code a little bit more carefully

270
00:14:50,540 --> 00:14:53,890
to make sure 100% that you understand

271
00:14:53,890 --> 00:14:58,530
especially this last example that we just worked on, okay.

272
00:14:58,530 --> 00:15:01,830
But anyway, great job in completing this challenge

273
00:15:01,830 --> 00:15:04,573
and now I see you in the next video.

