All language subtitles for 19. Coding Challenge9 3

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (SoranĂ®)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1 1

And now, it's time for coding challenge number three. 2

2

And we are still working 3

3

on our football betting application. 4

4

Now this time, we have this map down here. 5

5

So this one, which contains all the events that happened 6

6

during the game. 7

7

So the values here are the events themselves, 8

8

for example, a goal or a substitution, 9

9

and the keys are the minutes, in which the event occurs. 10

10

And just notice, that a football game has 90 minutes, 11

11

plus some extra time. 12

12

So this might be a little bit over 90, 13

13

but usually it's always 90 minutes, 14

14

in case you're not familiar with this beautiful game. 15

15

Anyway, your tasks are to create an array called events, 16

16

which will contain all the different game events 17

17

that happened during this game. 18

18

And that means no duplicates in that array. 19

19

Now, after the game has finished, 20

20

it was found that the yellow card from minute 64 was unfair. 21

21

So please just remove this event from the log. 22

22

Next up print dis string to the console. 23

23

An event happened on average every nine minutes. 24

24

And of course, your task is to calculate this nine minutes, 25

25

keeping in mind, that a game has 90 minutes. 26

26

Finally, loop over the events, 27

27

and then log into the console. 28

28

And what's tricky about this, is that you should mark 29

29

whether they happened in the first half of the game, 30

30

or the second half. 31

31

And the second half means, 32

32

that it happened after 45 minutes. 33

33

So it should look something like this. 34

34

So I believe that this challenge is a little bit easier 35

35

than the previous one, 36

36

and so hopefully you can manage to complete 37

37

all of these four tasks. 38

38

So I'll see you once you're done. 39

39

So, I hope that was fun. 40

40

So let's get started immediately with the solution here. 41

41

So we should create an array called events, 42

42

with the unique events. 43

43

So basically, that's the unique values of all of these here. 44

44

Now, what are these values here? 45

45

They are essentially the values of this map, right? 46

46

So, what I'm saying, is that they are 47

47

in gameEvents.values. 48

48

And we learned about this one 49

49

kind of by the end of the last video. 50

50

So let's comment out this one here. 51

51

And so indeed, we see that this is what contains 52

52

the values that we are interested in. 53

53

Alright. 54

54

So, let's say gameEvents.values, 55

55

and this is our starting point, 56

56

and now to get the unique values here, 57

57

we basically need to create a set, out of this, right? 58

58

That's the main use case of sets. 59

59

So, new set, but this alone is not going to be enough, 60

60

but let's still take a look, 61

61

at this for now, 62

62

and beautiful. 63

63

So, indeed we have a set with the only 64

64

four events that happened. 65

65

So, there were only goals, substitutions yellow cards 66

66

and red cards. 67

67

And now to convert us to an array, we do adjust like before. 68

68

Create a new array, 69

69

and a spread operator to unpack this set, 70

70

and then we are done. 71

71

Next up, this one is the easiest one, 72

72

so it tells us to delete the event from minute 64. 73

73

So that's very easy. 74

74

So gameEvents.delete, 75

75

and now all we have to do is to use that exact key, 76

76

and then that event will be gone. 77

77

Great. The next one is just as easy I believe. 78

78

So let's just grab this from here. 79

79

And now we just need to calculate this actual average. 80

80

And how do we do that? 81

81

So basically, to say that an event happened every X minutes, 82

82

we simply need to divide the number of events by 90 minutes. 83

83

So the duration of the game. 84

84

So, we see here 85

85

that we have three, six, nine, eleven events. 86

86

So, how can we count that programmatically? 87

87

Well, for that we have gameEvents.size, remember? 88

88

And now we just divide that by 90, 89

89

and with that, we get this weird number 90

90

and that's because in fact we need the opposite. 91

91

So we need to say 92

92

90 minutes divided by how many events there happened, 93

93

to say that on average, 94

94

something happened every nine minutes. 95

95

Now, if we want it to be really specific, 96

96

then this game actually lasted 92 minutes. 97

97

So, how do we get that value? 98

98

So this is just a bonus, Okay? 99

99

I didn't expect you to do this one. 100

100

So this 92, is essentially the last 101

101

of the keys of the map. 102

102

I'm sold. Let's get the keys. 103

103

So, that's gameEvents.keys. 104

104

And as always, we need to convert this to an array. 105

105

So, using all the tools that we already learned. 106

106

So just to make sure, 107

107

indeed it is. 108

108

And now we want the last value. 109

109

And how can we get the last value? 110

110

Do you remember that? 111

111

Well, we can use the pop method. 112

112

And in the past, we mainly used the pop method, 113

113

to simply delete the last element of the array. 114

114

But also, back then I told you, 115

115

that it also returns, that deleted array. 116

116

Or actually that deleted element. 117

117

And so, here we can take the advantage of that. 118

118

So, this here is an array now, 119

119

and so on that, we can call pop. 120

120

And so that will take, the last element out of the array 121

121

and give it to us. 122

122

So that's 92. 123

123

And so to make this really accurate, 124

124

here we can now say, time. 125

125

Okay. And so this, is even better right now, 126

126

but again, this is just kind of a bonus 127

127

just to show you some more nice little tricks. 128

128

Anyway. Now our goal is to loop through the object, 129

129

or actually through the map. 130

130

And so this is pretty standard now at this point. 131

131

Here we are missing the off. 132

132

So just like we did in the last video, 133

133

and now all we need to do, is to figure out the half. 134

134

So if it's the first half, or the second half. 135

135

So, what we want to lock to the console is this. 136

136

And then so, either a first or second half, 137

137

and then the minute, 138

138

I believe, let's see. 139

139

Yeah. So, the minute and then colon, and then the event. 140

140

So let's actually make these here more specific, 141

141

so a minute and event. 142

142

So that makes it easier to read the code. 143

143

So minute and event. 144

144

And now here, let's just again, create an external variable, 145

145

which I'm going to call the Half. 146

146

And let's use the turnery operator here again, 147

147

so if the minute is below or equal 45, 148

148

then it is the first, 149

149

otherwise it's the second, 150

150

and that's it. 151

151

And, that worked just fine once again. Okay. 152

152

So, I hope that made sense, 153

153

in case it didn't, then it's always just analyze the code, 154

154

or you can also just ask some questions in the Q and A area. 155

155

Anyway, we're now almost done with this section. 156

156

Next up, all we have left to do is to work with strengths, 157

157

which is also a really nice and really interesting topic 158

158

that we need in JavaScript all the time. 159

159

So make sure to follow me there, right away.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.