All language subtitles for 19. Coding Challenge9 3

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 1 00:00:01,290 --> 00:00:05,633 And now, it's time for coding challenge number three. 2 2 00:00:07,380 --> 00:00:08,970 And we are still working 3 3 00:00:08,970 --> 00:00:11,700 on our football betting application. 4 4 00:00:11,700 --> 00:00:15,850 Now this time, we have this map down here. 5 5 00:00:15,850 --> 00:00:19,590 So this one, which contains all the events that happened 6 6 00:00:19,590 --> 00:00:21,360 during the game. 7 7 00:00:21,360 --> 00:00:24,370 So the values here are the events themselves, 8 8 00:00:24,370 --> 00:00:27,680 for example, a goal or a substitution, 9 9 00:00:27,680 --> 00:00:31,833 and the keys are the minutes, in which the event occurs. 10 10 00:00:32,790 --> 00:00:37,270 And just notice, that a football game has 90 minutes, 11 11 00:00:37,270 --> 00:00:39,180 plus some extra time. 12 12 00:00:39,180 --> 00:00:41,650 So this might be a little bit over 90, 13 13 00:00:41,650 --> 00:00:43,980 but usually it's always 90 minutes, 14 14 00:00:43,980 --> 00:00:47,563 in case you're not familiar with this beautiful game. 15 15 00:00:48,630 --> 00:00:53,020 Anyway, your tasks are to create an array called events, 16 16 00:00:53,020 --> 00:00:55,410 which will contain all the different game events 17 17 00:00:55,410 --> 00:00:57,830 that happened during this game. 18 18 00:00:57,830 --> 00:01:00,983 And that means no duplicates in that array. 19 19 00:01:01,960 --> 00:01:03,970 Now, after the game has finished, 20 20 00:01:03,970 --> 00:01:08,970 it was found that the yellow card from minute 64 was unfair. 21 21 00:01:09,050 --> 00:01:12,810 So please just remove this event from the log. 22 22 00:01:12,810 --> 00:01:16,260 Next up print dis string to the console. 23 23 00:01:16,260 --> 00:01:19,000 An event happened on average every nine minutes. 24 24 00:01:19,000 --> 00:01:23,890 And of course, your task is to calculate this nine minutes, 25 25 00:01:23,890 --> 00:01:27,473 keeping in mind, that a game has 90 minutes. 26 26 00:01:28,440 --> 00:01:31,380 Finally, loop over the events, 27 27 00:01:31,380 --> 00:01:33,320 and then log into the console. 28 28 00:01:33,320 --> 00:01:36,180 And what's tricky about this, is that you should mark 29 29 00:01:36,180 --> 00:01:39,010 whether they happened in the first half of the game, 30 30 00:01:39,010 --> 00:01:40,740 or the second half. 31 31 00:01:40,740 --> 00:01:43,130 And the second half means, 32 32 00:01:43,130 --> 00:01:46,003 that it happened after 45 minutes. 33 33 00:01:46,990 --> 00:01:49,123 So it should look something like this. 34 34 00:01:50,380 --> 00:01:53,380 So I believe that this challenge is a little bit easier 35 35 00:01:53,380 --> 00:01:54,760 than the previous one, 36 36 00:01:54,760 --> 00:01:57,570 and so hopefully you can manage to complete 37 37 00:01:57,570 --> 00:01:59,320 all of these four tasks. 38 38 00:01:59,320 --> 00:02:01,463 line:15% So I'll see you once you're done. 39 39 00:02:05,670 --> 00:02:09,160 So, I hope that was fun. 40 40 00:02:09,160 --> 00:02:12,540 So let's get started immediately with the solution here. 41 41 00:02:12,540 --> 00:02:16,380 So we should create an array called events, 42 42 00:02:16,380 --> 00:02:18,720 with the unique events. 43 43 00:02:18,720 --> 00:02:23,720 So basically, that's the unique values of all of these here. 44 44 00:02:24,460 --> 00:02:27,100 Now, what are these values here? 45 45 00:02:27,100 --> 00:02:31,270 They are essentially the values of this map, right? 46 46 00:02:31,270 --> 00:02:34,660 So, what I'm saying, is that they are 47 47 00:02:34,660 --> 00:02:39,660 in gameEvents.values. 48 48 00:02:40,020 --> 00:02:42,010 And we learned about this one 49 49 00:02:42,010 --> 00:02:44,893 kind of by the end of the last video. 50 50 00:02:46,870 --> 00:02:49,070 So let's comment out this one here. 51 51 00:02:49,070 --> 00:02:52,820 And so indeed, we see that this is what contains 52 52 00:02:52,820 --> 00:02:55,733 the values that we are interested in. 53 53 00:02:57,260 --> 00:02:58,093 Alright. 54 54 00:02:59,130 --> 00:03:02,713 So, let's say gameEvents.values, 55 55 00:03:05,280 --> 00:03:07,510 and this is our starting point, 56 56 00:03:07,510 --> 00:03:09,870 and now to get the unique values here, 57 57 00:03:09,870 --> 00:03:14,690 we basically need to create a set, out of this, right? 58 58 00:03:14,690 --> 00:03:17,183 That's the main use case of sets. 59 59 00:03:18,580 --> 00:03:23,480 So, new set, but this alone is not going to be enough, 60 60 00:03:23,480 --> 00:03:24,963 but let's still take a look, 61 61 00:03:27,860 --> 00:03:28,923 at this for now, 62 62 00:03:30,760 --> 00:03:32,370 and beautiful. 63 63 00:03:32,370 --> 00:03:34,770 So, indeed we have a set with the only 64 64 00:03:34,770 --> 00:03:37,450 four events that happened. 65 65 00:03:37,450 --> 00:03:40,890 So, there were only goals, substitutions yellow cards 66 66 00:03:40,890 --> 00:03:42,083 and red cards. 67 67 00:03:43,030 --> 00:03:47,330 And now to convert us to an array, we do adjust like before. 68 68 00:03:47,330 --> 00:03:49,090 Create a new array, 69 69 00:03:49,090 --> 00:03:53,270 and a spread operator to unpack this set, 70 70 00:03:53,270 --> 00:03:54,863 and then we are done. 71 71 00:03:56,960 --> 00:04:01,310 Next up, this one is the easiest one, 72 72 00:04:01,310 --> 00:04:05,963 so it tells us to delete the event from minute 64. 73 73 00:04:06,900 --> 00:04:09,090 So that's very easy. 74 74 00:04:09,090 --> 00:04:13,460 So gameEvents.delete, 75 75 00:04:13,460 --> 00:04:17,530 and now all we have to do is to use that exact key, 76 76 00:04:17,530 --> 00:04:20,350 and then that event will be gone. 77 77 00:04:20,350 --> 00:04:24,343 Great. The next one is just as easy I believe. 78 78 00:04:26,550 --> 00:04:28,903 So let's just grab this from here. 79 79 00:04:33,757 --> 00:04:38,257 And now we just need to calculate this actual average. 80 80 00:04:39,150 --> 00:04:40,463 And how do we do that? 81 81 00:04:41,640 --> 00:04:46,640 So basically, to say that an event happened every X minutes, 82 82 00:04:47,160 --> 00:04:51,320 we simply need to divide the number of events by 90 minutes. 83 83 00:04:51,320 --> 00:04:52,923 So the duration of the game. 84 84 00:04:54,050 --> 00:04:54,910 So, we see here 85 85 00:04:54,910 --> 00:04:59,910 that we have three, six, nine, eleven events. 86 86 00:05:00,110 --> 00:05:02,993 So, how can we count that programmatically? 87 87 00:05:04,120 --> 00:05:07,840 line:15% Well, for that we have gameEvents.size, remember? 88 88 00:05:11,510 --> 00:05:15,150 line:15% And now we just divide that by 90, 89 89 00:05:15,150 --> 00:05:18,730 line:15% and with that, we get this weird number 90 90 00:05:18,730 --> 00:05:22,480 line:15% and that's because in fact we need the opposite. 91 91 00:05:22,480 --> 00:05:23,660 line:15% So we need to say 92 92 00:05:23,660 --> 00:05:28,660 line:15% 90 minutes divided by how many events there happened, 93 93 00:05:29,620 --> 00:05:31,640 line:15% to say that on average, 94 94 00:05:31,640 --> 00:05:33,663 line:15% something happened every nine minutes. 95 95 00:05:35,040 --> 00:05:38,050 Now, if we want it to be really specific, 96 96 00:05:38,050 --> 00:05:41,630 then this game actually lasted 92 minutes. 97 97 00:05:41,630 --> 00:05:44,183 So, how do we get that value? 98 98 00:05:46,560 --> 00:05:48,770 So this is just a bonus, Okay? 99 99 00:05:48,770 --> 00:05:52,310 I didn't expect you to do this one. 100 100 00:05:52,310 --> 00:05:55,150 So this 92, is essentially the last 101 101 00:05:55,150 --> 00:05:57,193 of the keys of the map. 102 102 00:05:58,450 --> 00:06:00,560 I'm sold. Let's get the keys. 103 103 00:06:00,560 --> 00:06:05,490 line:15% So, that's gameEvents.keys. 104 104 00:06:05,490 --> 00:06:09,033 And as always, we need to convert this to an array. 105 105 00:06:11,500 --> 00:06:13,943 line:15% So, using all the tools that we already learned. 106 106 00:06:16,040 --> 00:06:17,393 line:15% So just to make sure, 107 107 00:06:19,580 --> 00:06:21,270 line:15% indeed it is. 108 108 00:06:21,270 --> 00:06:23,880 And now we want the last value. 109 109 00:06:23,880 --> 00:06:26,270 And how can we get the last value? 110 110 00:06:26,270 --> 00:06:28,210 Do you remember that? 111 111 00:06:28,210 --> 00:06:31,180 Well, we can use the pop method. 112 112 00:06:31,180 --> 00:06:34,440 And in the past, we mainly used the pop method, 113 113 00:06:34,440 --> 00:06:37,540 to simply delete the last element of the array. 114 114 00:06:37,540 --> 00:06:39,690 But also, back then I told you, 115 115 00:06:39,690 --> 00:06:42,743 that it also returns, that deleted array. 116 116 00:06:43,880 --> 00:06:46,280 Or actually that deleted element. 117 117 00:06:46,280 --> 00:06:49,860 And so, here we can take the advantage of that. 118 118 00:06:49,860 --> 00:06:52,500 line:15% So, this here is an array now, 119 119 00:06:52,500 --> 00:06:54,883 line:15% and so on that, we can call pop. 120 120 00:06:56,340 --> 00:06:59,640 line:15% And so that will take, the last element out of the array 121 121 00:06:59,640 --> 00:07:00,693 line:15% and give it to us. 122 122 00:07:01,640 --> 00:07:03,100 line:15% So that's 92. 123 123 00:07:03,100 --> 00:07:05,253 And so to make this really accurate, 124 124 00:07:07,180 --> 00:07:10,293 here we can now say, time. 125 125 00:07:12,890 --> 00:07:16,710 line:15% Okay. And so this, is even better right now, 126 126 00:07:16,710 --> 00:07:19,850 but again, this is just kind of a bonus 127 127 00:07:19,850 --> 00:07:23,090 just to show you some more nice little tricks. 128 128 00:07:23,090 --> 00:07:27,013 Anyway. Now our goal is to loop through the object, 129 129 00:07:28,510 --> 00:07:30,073 or actually through the map. 130 130 00:07:34,130 --> 00:07:37,683 And so this is pretty standard now at this point. 131 131 00:07:40,740 --> 00:07:42,573 Here we are missing the off. 132 132 00:07:43,500 --> 00:07:46,810 So just like we did in the last video, 133 133 00:07:46,810 --> 00:07:50,880 and now all we need to do, is to figure out the half. 134 134 00:07:50,880 --> 00:07:53,823 So if it's the first half, or the second half. 135 135 00:07:56,050 --> 00:07:59,490 So, what we want to lock to the console is this. 136 136 00:07:59,490 --> 00:08:02,163 And then so, either a first or second half, 137 137 00:08:06,230 --> 00:08:07,523 and then the minute, 138 138 00:08:08,370 --> 00:08:09,593 I believe, let's see. 139 139 00:08:10,580 --> 00:08:14,423 Yeah. So, the minute and then colon, and then the event. 140 140 00:08:15,800 --> 00:08:18,860 So let's actually make these here more specific, 141 141 00:08:18,860 --> 00:08:21,710 so a minute and event. 142 142 00:08:21,710 --> 00:08:23,760 So that makes it easier to read the code. 143 143 00:08:25,910 --> 00:08:29,313 So minute and event. 144 144 00:08:30,280 --> 00:08:33,803 And now here, let's just again, create an external variable, 145 145 00:08:34,730 --> 00:08:36,380 which I'm going to call the Half. 146 146 00:08:41,170 --> 00:08:44,210 And let's use the turnery operator here again, 147 147 00:08:44,210 --> 00:08:48,683 so if the minute is below or equal 45, 148 148 00:08:50,520 --> 00:08:54,300 then it is the first, 149 149 00:08:54,300 --> 00:08:57,393 otherwise it's the second, 150 150 00:08:59,030 --> 00:09:00,680 and that's it. 151 151 00:09:00,680 --> 00:09:04,753 And, that worked just fine once again. Okay. 152 152 00:09:07,130 --> 00:09:09,620 So, I hope that made sense, 153 153 00:09:09,620 --> 00:09:13,010 in case it didn't, then it's always just analyze the code, 154 154 00:09:13,010 --> 00:09:17,970 or you can also just ask some questions in the Q and A area. 155 155 00:09:17,970 --> 00:09:21,630 Anyway, we're now almost done with this section. 156 156 00:09:21,630 --> 00:09:25,550 Next up, all we have left to do is to work with strengths, 157 157 00:09:25,550 --> 00:09:28,990 which is also a really nice and really interesting topic 158 158 00:09:28,990 --> 00:09:31,930 that we need in JavaScript all the time. 159 159 00:09:31,930 --> 00:09:34,783 So make sure to follow me there, right away. 13751

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