1
00:00:01,280 --> 00:00:05,650
<v ->Welcome to the first coding challenge of this section.</v>

2
00:00:05,650 --> 00:00:08,383
And this one is gonna be an exciting one.

3
00:00:10,160 --> 00:00:11,450
Because in this one,

4
00:00:11,450 --> 00:00:14,980
we are building a simple Pol application.

5
00:00:14,980 --> 00:00:17,370
So a pol has a question,

6
00:00:17,370 --> 00:00:20,790
an array of options from which people can choose,

7
00:00:20,790 --> 00:00:25,270
and an array with the number of replies for each option.

8
00:00:25,270 --> 00:00:28,240
And this data is stored in this object here

9
00:00:28,240 --> 00:00:30,430
that it already created for you.

10
00:00:30,430 --> 00:00:32,960
Now you can copy this object from here,

11
00:00:32,960 --> 00:00:35,110
or you can get it from the final code

12
00:00:35,110 --> 00:00:38,723
that's available for the section in the GitHub repository.

13
00:00:40,130 --> 00:00:43,180
Now, okay, so you see, we have to question,

14
00:00:43,180 --> 00:00:48,180
the array of options, and also a new array of answers.

15
00:00:48,840 --> 00:00:50,040
So this code here,

16
00:00:50,040 --> 00:00:52,660
we will learn how it works in the next lecture.

17
00:00:52,660 --> 00:00:57,180
But this will create this array of four zeros.

18
00:00:57,180 --> 00:01:00,360
And that's because there are four options here,

19
00:01:00,360 --> 00:01:01,473
for this question.

20
00:01:03,900 --> 00:01:06,520
And now, here are your tasks.

21
00:01:06,520 --> 00:01:09,340
So first up in that poll object,

22
00:01:09,340 --> 00:01:13,040
create a new method called register new answer.

23
00:01:13,040 --> 00:01:15,990
And this method does two things.

24
00:01:15,990 --> 00:01:17,770
So displays a prompt window

25
00:01:17,770 --> 00:01:21,500
for the user to input the number of the selected option.

26
00:01:21,500 --> 00:01:25,163
And here, I want the text to look exactly like this.

27
00:01:26,200 --> 00:01:27,159
Then,

28
00:01:27,159 --> 00:01:30,210
based on the inputted number,

29
00:01:30,210 --> 00:01:34,750
so the user should input either zero, one, two or three.

30
00:01:34,750 --> 00:01:37,863
So based on that, update the answers array.

31
00:01:38,800 --> 00:01:40,670
So if the user,

32
00:01:40,670 --> 00:01:42,479
gives three here,

33
00:01:42,479 --> 00:01:43,770
as the option,

34
00:01:43,770 --> 00:01:47,850
then increase the value at position three of the array.

35
00:01:47,850 --> 00:01:50,223
And of course, increase that by one.

36
00:01:51,580 --> 00:01:55,410
To do this, make sure that the input is actually a number.

37
00:01:55,410 --> 00:01:57,793
And if that number makes sense,

38
00:02:00,600 --> 00:02:03,150
then I want you to call this method,

39
00:02:03,150 --> 00:02:06,580
whenever the user clicks on this button.

40
00:02:06,580 --> 00:02:09,170
And so this is where the second button here,

41
00:02:09,170 --> 00:02:10,573
comes into play.

42
00:02:11,720 --> 00:02:16,240
Then number three, create a method called display results.

43
00:02:16,240 --> 00:02:19,150
And this one, should, as the name says,

44
00:02:19,150 --> 00:02:21,460
display the results of the poll.

45
00:02:21,460 --> 00:02:25,080
Now this method takes an argument called type.

46
00:02:25,080 --> 00:02:29,390
And that type should be a string, as I say, here,

47
00:02:29,390 --> 00:02:32,900
and the value of that string should either be string,

48
00:02:32,900 --> 00:02:34,060
or array.

49
00:02:34,060 --> 00:02:37,410
So these are two different ways of displaying the results,

50
00:02:37,410 --> 00:02:38,730
basically.

51
00:02:38,730 --> 00:02:42,260
Now, if the type is set to the string of array,

52
00:02:42,260 --> 00:02:45,590
then simply display the results array as it is,

53
00:02:45,590 --> 00:02:48,290
using a normal console dot log.

54
00:02:48,290 --> 00:02:51,890
And this should actually be the default option.

55
00:02:51,890 --> 00:02:56,130
All right. Now, if the type is set to string,

56
00:02:56,130 --> 00:02:59,883
then display a string like this one here.

57
00:03:00,870 --> 00:03:05,490
Okay. And then once you have this method built,

58
00:03:05,490 --> 00:03:10,190
run it each time after the register a new answer.

59
00:03:10,190 --> 00:03:11,350
So essentially,

60
00:03:11,350 --> 00:03:14,653
whenever someone clicks on this button here,

61
00:03:15,740 --> 00:03:17,340
it will call this;

62
00:03:19,748 --> 00:03:21,660
there's register a new answer method.

63
00:03:21,660 --> 00:03:26,660
And then this method itself will call display results.

64
00:03:27,070 --> 00:03:29,220
Okay. And to do this,

65
00:03:29,220 --> 00:03:33,360
use as many of the tools that you learned in this section,

66
00:03:33,360 --> 00:03:35,760
and probably also the last sections,

67
00:03:35,760 --> 00:03:38,583
and really all the course itself.

68
00:03:39,430 --> 00:03:43,450
Now, there are a lot of moving parts in this challenge.

69
00:03:43,450 --> 00:03:47,250
And it might not be as straightforward as it seems here.

70
00:03:47,250 --> 00:03:49,190
So if you need to cut some corners,

71
00:03:49,190 --> 00:03:51,570
and make some things a little bit easier,

72
00:03:51,570 --> 00:03:53,740
then that's absolutely no problem.

73
00:03:53,740 --> 00:03:55,920
At least just write some code on your own.

74
00:03:55,920 --> 00:03:58,403
That's really my main goal with this challenge.

75
00:03:59,280 --> 00:04:02,530
Then if you manage to do these challenges,

76
00:04:02,530 --> 00:04:05,320
or to do the challenge as instructed here,

77
00:04:05,320 --> 00:04:07,630
then I also have a bonus for you.

78
00:04:07,630 --> 00:04:11,750
And so that is to use these display results method,

79
00:04:11,750 --> 00:04:15,599
that you built before to display these two arrays,

80
00:04:15,599 --> 00:04:17,703
that we have here in the test data.

81
00:04:18,720 --> 00:04:20,830
Okay. So usually,

82
00:04:20,830 --> 00:04:24,210
you simply use this method to display

83
00:04:24,210 --> 00:04:28,490
the answers array that's inside of the object.

84
00:04:28,490 --> 00:04:32,250
But here, I want you to really display simply this array,

85
00:04:32,250 --> 00:04:33,950
and this array.

86
00:04:33,950 --> 00:04:34,970
And of course,

87
00:04:34,970 --> 00:04:39,970
do not put this array here inside of this poll object.

88
00:04:40,150 --> 00:04:42,910
Okay, you should use them individually.

89
00:04:42,910 --> 00:04:43,960
Now, for doing this,

90
00:04:43,960 --> 00:04:45,750
you have to really think about

91
00:04:45,750 --> 00:04:49,430
what the disk keyword should look like in this situation.

92
00:04:49,430 --> 00:04:50,890
And then you need to,

93
00:04:50,890 --> 00:04:54,653
and then you basically need to set this keyword accordingly.

94
00:04:55,530 --> 00:04:58,810
Now, okay, so that's a nice challenge here,

95
00:04:58,810 --> 00:05:01,400
and one thing that is certain is that,

96
00:05:01,400 --> 00:05:04,780
your code will look different than mine.

97
00:05:04,780 --> 00:05:07,950
I'm just a normal developer like anyone else,

98
00:05:07,950 --> 00:05:10,400
and everybody writes their own code.

99
00:05:10,400 --> 00:05:14,210
And so my code is different from everyone else's code,

100
00:05:14,210 --> 00:05:15,360
probably.

101
00:05:15,360 --> 00:05:17,720
And so yeah, that's completely normal,

102
00:05:17,720 --> 00:05:21,120
if you are starting to develop your own style.

103
00:05:21,120 --> 00:05:24,240
So take maybe an hour even to do all of this,

104
00:05:24,240 --> 00:05:27,653
and then come back to this video to check out my solution.

105
00:05:31,360 --> 00:05:36,330
So let's get to work here. I hope it went well for you,

106
00:05:36,330 --> 00:05:37,933
when you try it out on your own.

107
00:05:39,330 --> 00:05:42,683
And you can always share your experience in the q&amp;a area.

108
00:05:43,940 --> 00:05:47,000
Anyway, let's now get the answer here.

109
00:05:47,000 --> 00:05:48,823
And so for that we use prompt.

110
00:05:49,810 --> 00:05:51,320
So const,

111
00:05:51,320 --> 00:05:52,153
answer,

112
00:05:53,420 --> 00:05:54,253
prompt.

113
00:05:55,500 --> 00:05:59,030
And so, let's see what it has to look like.

114
00:05:59,030 --> 00:06:01,120
So it's just a question,

115
00:06:01,120 --> 00:06:03,030
then it's a new line,

116
00:06:03,030 --> 00:06:04,340
then it's these options,

117
00:06:04,340 --> 00:06:07,770
another new line, and then right up to number.

118
00:06:07,770 --> 00:06:09,750
So this part is always the same.

119
00:06:09,750 --> 00:06:11,963
So I'm just copying it from here.

120
00:06:14,150 --> 00:06:16,653
So, we want to grab the question first.

121
00:06:17,860 --> 00:06:19,650
And so that is,

122
00:06:19,650 --> 00:06:20,483
this,

123
00:06:21,340 --> 00:06:22,323
dot question.

124
00:06:23,550 --> 00:06:26,940
Then the new line, which is this, remember,

125
00:06:26,940 --> 00:06:28,900
then we want the options.

126
00:06:28,900 --> 00:06:32,803
And so one new line for each of these options here.

127
00:06:33,660 --> 00:06:37,290
So this is an array, we want to transform it to a string.

128
00:06:37,290 --> 00:06:40,790
And so for that, we use the join method.

129
00:06:40,790 --> 00:06:44,520
So this one we learned about in the previous section.

130
00:06:44,520 --> 00:06:46,423
So I hope you remember this one.

131
00:06:47,330 --> 00:06:52,233
And so we take the options array here and join it.

132
00:06:53,110 --> 00:06:57,363
And we do join it again by the newline character.

133
00:06:59,160 --> 00:07:02,893
Now, okay, and then finally, another new line.

134
00:07:04,263 --> 00:07:05,213
And then this part.

135
00:07:06,440 --> 00:07:09,090
Now, right? Oh, and then we of course,

136
00:07:09,090 --> 00:07:13,293
also need to convert this result to a number.

137
00:07:14,590 --> 00:07:17,230
All right. So this looks good.

138
00:07:17,230 --> 00:07:21,653
Let's just add a comment here. So this is get the answer.

139
00:07:23,434 --> 00:07:26,093
And then here second, is to,

140
00:07:27,150 --> 00:07:28,083
register.

141
00:07:28,920 --> 00:07:29,753
I think that's,

142
00:07:30,730 --> 00:07:32,073
what we had here.

143
00:07:33,700 --> 00:07:35,750
So the first step is to get the answer.

144
00:07:35,750 --> 00:07:39,253
And the second is to basically update the answers.

145
00:07:40,530 --> 00:07:42,923
So I'm just calling that register the answer.

146
00:07:45,790 --> 00:07:50,663
Okay, but here, let's actually start by trying it out.

147
00:07:51,500 --> 00:07:53,380
So let's do for now, poll dot

148
00:07:54,900 --> 00:07:57,303
register new answer.

149
00:07:59,430 --> 00:08:00,263
And indeed,

150
00:08:00,263 --> 00:08:04,180
this is exactly the formatting we were looking for,

151
00:08:04,180 --> 00:08:07,323
let's say three. And indeed, we get three.

152
00:08:08,580 --> 00:08:09,413
Nice.

153
00:08:11,390 --> 00:08:13,750
And so now let's register the answer.

154
00:08:13,750 --> 00:08:15,630
And remember that we should check,

155
00:08:15,630 --> 00:08:18,530
if this value is actually a number.

156
00:08:18,530 --> 00:08:21,500
And also, if it makes actually sense.

157
00:08:21,500 --> 00:08:23,603
So in terms of the number of options.

158
00:08:25,070 --> 00:08:29,530
So first, we check if it is indeed a number.

159
00:08:29,530 --> 00:08:31,790
And there are better ways of checking this,

160
00:08:31,790 --> 00:08:33,313
but more about that later.

161
00:08:34,270 --> 00:08:36,703
And we also want to know if the answer,

162
00:08:37,669 --> 00:08:42,630
is below the length of this array, basically. Right?

163
00:08:42,630 --> 00:08:46,840
So if the answer is 10, then that doesn't make any sense.

164
00:08:46,840 --> 00:08:49,290
And so it must stay below the length.

165
00:08:49,290 --> 00:08:51,060
So the length here is four.

166
00:08:51,060 --> 00:08:55,740
And so the max reply that we accept is three.

167
00:08:55,740 --> 00:08:58,983
So answer needs to stay below this dot answers,

168
00:09:00,200 --> 00:09:02,230
dot length.

169
00:09:02,230 --> 00:09:05,090
Now here, we could not do an if statement,

170
00:09:05,090 --> 00:09:08,460
and basically saying that if this is true,

171
00:09:08,460 --> 00:09:13,220
then increase the answers array at the correct position.

172
00:09:13,220 --> 00:09:14,670
However, instead,

173
00:09:14,670 --> 00:09:18,320
this is actually a great use case for short circuiting,

174
00:09:18,320 --> 00:09:20,163
with the end operator.

175
00:09:21,950 --> 00:09:26,510
So let's simply do this. So this dot answers,

176
00:09:26,510 --> 00:09:29,403
and then we go to the position of answer,

177
00:09:31,420 --> 00:09:34,670
and then simply increase it like this.

178
00:09:34,670 --> 00:09:38,710
Now, all right, so if this is true,

179
00:09:38,710 --> 00:09:41,565
then the end operator will keep going. Right?

180
00:09:41,565 --> 00:09:45,350
And so then this is evaluated, and if it's still true,

181
00:09:45,350 --> 00:09:47,800
then this here is executed.

182
00:09:47,800 --> 00:09:51,150
But if either one of these conditions here is false,

183
00:09:51,150 --> 00:09:53,980
then the end operator will short circuit,

184
00:09:53,980 --> 00:09:56,850
and this part here is not executed.

185
00:09:56,850 --> 00:10:00,800
So this is a nice use case for short circuiting,

186
00:10:00,800 --> 00:10:03,230
because the code that we want to execute,

187
00:10:03,230 --> 00:10:06,030
is just one simple line of code.

188
00:10:06,030 --> 00:10:08,850
Now, okay. So now let's,

189
00:10:08,850 --> 00:10:10,250
then,

190
00:10:10,250 --> 00:10:11,813
take a look at the answers.

191
00:10:12,800 --> 00:10:14,573
So this dot answers.

192
00:10:16,920 --> 00:10:21,030
So this is for now, the register a new answer method.

193
00:10:21,030 --> 00:10:24,750
And now let's focus here on point number two,

194
00:10:24,750 --> 00:10:26,930
which is to actually call the method,

195
00:10:26,930 --> 00:10:30,473
whenever we click on this ENTER button here.

196
00:10:32,360 --> 00:10:33,370
So,

197
00:10:33,370 --> 00:10:35,623
let's select that button,

198
00:10:36,900 --> 00:10:39,163
document dot query selector.

199
00:10:40,420 --> 00:10:42,750
And now we need the class name.

200
00:10:42,750 --> 00:10:45,200
Let's check that out here again, in the elements.

201
00:10:46,220 --> 00:10:48,493
And so it has the class of poll.

202
00:10:51,000 --> 00:10:52,063
So poll,

203
00:10:53,680 --> 00:10:55,523
dot @ event listener.

204
00:10:56,400 --> 00:11:00,780
Click, and now the function that we want to execute.

205
00:11:00,780 --> 00:11:03,060
And so that is @ poll

206
00:11:03,060 --> 00:11:04,610
dot

207
00:11:04,610 --> 00:11:07,270
register new answer.

208
00:11:07,270 --> 00:11:11,363
All right. Now, do you think that this will work like this?

209
00:11:12,320 --> 00:11:14,070
And let's give it a save, actually.

210
00:11:15,000 --> 00:11:17,230
And there is an error.

211
00:11:17,230 --> 00:11:20,190
And that's because we're trying to read property join,

212
00:11:20,190 --> 00:11:23,640
of undefined, right here.

213
00:11:23,640 --> 00:11:26,900
And so the problem here is, as you might have guessed,

214
00:11:26,900 --> 00:11:29,130
because we talked about this before,

215
00:11:29,130 --> 00:11:34,130
is that the disk keyword right now, points to this element.

216
00:11:34,190 --> 00:11:36,660
So to this poll button here.

217
00:11:36,660 --> 00:11:40,870
And so again, there is because in an event handler function,

218
00:11:40,870 --> 00:11:42,980
such as this one here,

219
00:11:42,980 --> 00:11:46,200
that this keyword will always point to the element,

220
00:11:46,200 --> 00:11:48,160
to which it is attached.

221
00:11:48,160 --> 00:11:51,220
And so right now, there is this button.

222
00:11:51,220 --> 00:11:55,120
So to fix this, we need to bind the disk keyword.

223
00:11:55,120 --> 00:11:59,170
And in this case, we need to set it to the poll object.

224
00:11:59,170 --> 00:12:02,410
And so then, in this function here,

225
00:12:02,410 --> 00:12:04,900
which is the result of the bind method,

226
00:12:04,900 --> 00:12:07,060
so in this new function,

227
00:12:07,060 --> 00:12:10,603
the disk keyword will then point to the poll object.

228
00:12:12,150 --> 00:12:15,720
So let's see that, and now indeed, it works.

229
00:12:15,720 --> 00:12:17,620
So that's input zero here.

230
00:12:17,620 --> 00:12:20,410
And indeed, we already get our array,

231
00:12:20,410 --> 00:12:23,640
where the count of the answers in position zero,

232
00:12:23,640 --> 00:12:26,630
has increased. And if we try this, again,

233
00:12:26,630 --> 00:12:27,993
it should become two.

234
00:12:29,030 --> 00:12:29,993
And it does.

235
00:12:31,570 --> 00:12:35,390
Now, in order to actually display these results,

236
00:12:35,390 --> 00:12:39,730
we should create this new method called display results.

237
00:12:39,730 --> 00:12:44,350
Now, right, so it takes a string that is called type,

238
00:12:44,350 --> 00:12:46,913
with array being the default here.

239
00:12:48,390 --> 00:12:49,223
Now, right.

240
00:12:50,360 --> 00:12:52,370
So let's do this.

241
00:12:52,370 --> 00:12:53,540
And also keep in mind,

242
00:12:53,540 --> 00:12:56,430
that this is the kind of string that we want,

243
00:12:56,430 --> 00:12:58,470
if the type is string.

244
00:12:58,470 --> 00:13:00,393
So let's copy this one.

245
00:13:01,560 --> 00:13:04,783
And now here, we add that new method called,

246
00:13:05,770 --> 00:13:06,743
display,

247
00:13:09,200 --> 00:13:10,083
results.

248
00:13:11,070 --> 00:13:12,563
And so it gets the type.

249
00:13:13,740 --> 00:13:18,480
And remember, it has the default set to array.

250
00:13:18,480 --> 00:13:21,830
And so here, we can use the ESX default parameters,

251
00:13:21,830 --> 00:13:24,043
using this equal sign.

252
00:13:25,020 --> 00:13:25,853
So,

253
00:13:25,853 --> 00:13:27,160
if,

254
00:13:27,160 --> 00:13:28,863
type equals,

255
00:13:29,780 --> 00:13:30,613
array,

256
00:13:32,710 --> 00:13:34,020
then simply log,

257
00:13:34,020 --> 00:13:34,870
this,

258
00:13:34,870 --> 00:13:35,703
dot,

259
00:13:36,600 --> 00:13:37,433
enters,

260
00:13:37,433 --> 00:13:38,990
to the console.

261
00:13:38,990 --> 00:13:40,130
Else,

262
00:13:40,130 --> 00:13:40,963
if,

263
00:13:42,510 --> 00:13:44,313
the type equals,

264
00:13:45,580 --> 00:13:46,413
string,

265
00:13:48,240 --> 00:13:51,653
then we want to log something like this to the console.

266
00:13:55,010 --> 00:13:59,023
So once more a template string, or template literal.

267
00:13:59,860 --> 00:14:01,740
And actually this would be outside

268
00:14:03,260 --> 00:14:04,620
results,

269
00:14:04,620 --> 00:14:05,453
are.

270
00:14:06,333 --> 00:14:08,440
And then to create this here,

271
00:14:08,440 --> 00:14:13,220
we can simply join the array together to form a string.

272
00:14:13,220 --> 00:14:17,653
So that's this dot results or actually answers,

273
00:14:20,490 --> 00:14:25,490
dot join, and we join them with a comma and a space.

274
00:14:26,220 --> 00:14:28,533
Now, okay, and so now here,

275
00:14:29,920 --> 00:14:32,090
let's get rid of this console dot log.

276
00:14:32,090 --> 00:14:35,320
And instead, we will now call this method.

277
00:14:35,320 --> 00:14:38,163
So this dot display results.

278
00:14:39,170 --> 00:14:41,190
And that's actually called twice.

279
00:14:41,190 --> 00:14:44,023
Once without passing any argument,

280
00:14:45,000 --> 00:14:47,860
and then here passing in,

281
00:14:47,860 --> 00:14:48,830
string,

282
00:14:48,830 --> 00:14:52,270
and so then we will see both types of results,

283
00:14:52,270 --> 00:14:54,370
printed to the console.

284
00:14:54,370 --> 00:14:55,283
And so this is,

285
00:14:56,560 --> 00:14:57,623
number four here.

286
00:14:59,230 --> 00:15:01,953
So, let's give it a save.

287
00:15:04,190 --> 00:15:08,173
Zero. And, indeed, it works just the same.

288
00:15:12,110 --> 00:15:13,003
Number three,

289
00:15:14,040 --> 00:15:15,920
let's try,

290
00:15:15,920 --> 00:15:17,040
three again.

291
00:15:17,040 --> 00:15:19,170
And so indeed, it works just fine.

292
00:15:19,170 --> 00:15:20,770
Let me now input something else.

293
00:15:21,850 --> 00:15:23,580
And so then nothing changes here.

294
00:15:23,580 --> 00:15:25,513
So the results are not updated.

295
00:15:26,410 --> 00:15:31,410
And that's because of this testing logic that we have here.

296
00:15:32,000 --> 00:15:36,523
Great. So I hope you have been following this far.

297
00:15:38,640 --> 00:15:41,290
So this is similar to what we have been doing.

298
00:15:41,290 --> 00:15:43,353
And now let's check out the bonus here.

299
00:15:44,230 --> 00:15:48,870
So let's use the display results method that we just use,

300
00:15:48,870 --> 00:15:51,480
but to display these two arrays.

301
00:15:51,480 --> 00:15:53,620
Okay, let's copy them just,

302
00:15:53,620 --> 00:15:56,170
so we don't have to scroll so much.

303
00:15:56,170 --> 00:15:59,470
And it says here that we should think about,

304
00:15:59,470 --> 00:16:02,240
what the disk keyword will look like.

305
00:16:02,240 --> 00:16:04,453
So we will do that, of course.

306
00:16:07,300 --> 00:16:11,403
Okay, so these are the arrays that we're gonna work with.

307
00:16:13,740 --> 00:16:14,573
So,

308
00:16:15,890 --> 00:16:20,530
the method is at Pol dot display results.

309
00:16:20,530 --> 00:16:21,660
But as I said,

310
00:16:21,660 --> 00:16:23,023
now, we want to call,

311
00:16:24,201 --> 00:16:28,240
this method here, not with this array.

312
00:16:28,240 --> 00:16:33,090
So not with the answers array, but instead with this array.

313
00:16:33,090 --> 00:16:35,370
So what should we do here?

314
00:16:35,370 --> 00:16:38,760
Well, we will have to use the call method,

315
00:16:38,760 --> 00:16:42,000
because we will need a new disk keyword, right?

316
00:16:42,000 --> 00:16:46,571
Because display results uses this dot answers.

317
00:16:46,571 --> 00:16:50,580
Okay, so the answers come from the disk keyword.

318
00:16:50,580 --> 00:16:53,660
And so if we want to have a different disk keyword,

319
00:16:53,660 --> 00:16:55,053
then we need to use call.

320
00:16:56,460 --> 00:16:59,320
And what should the disk keyword be like?

321
00:16:59,320 --> 00:17:00,820
Well, we need an object,

322
00:17:00,820 --> 00:17:04,060
which contains the answers property here, right?

323
00:17:04,060 --> 00:17:06,820
Otherwise, there is no way for this method,

324
00:17:06,820 --> 00:17:09,460
to call this dot answers.

325
00:17:09,460 --> 00:17:12,363
And so we can simply create a new object,

326
00:17:13,780 --> 00:17:16,343
and say, answers, and then,

327
00:17:17,490 --> 00:17:19,120
this,

328
00:17:19,120 --> 00:17:21,970
this array, and that's it.

329
00:17:21,970 --> 00:17:22,993
Let's try this.

330
00:17:23,990 --> 00:17:27,223
And indeed, here is the result printed.

331
00:17:28,250 --> 00:17:32,093
And that's even now passing us the, the string option.

332
00:17:34,270 --> 00:17:36,780
And so now Indeed, we get poll results are,

333
00:17:36,780 --> 00:17:39,500
five, two, and three.

334
00:17:39,500 --> 00:17:43,470
All right. So again, to recap, this works,

335
00:17:43,470 --> 00:17:48,470
because this function here is looking for this dot answers.

336
00:17:49,210 --> 00:17:52,510
But our array is, well, it's simply out here.

337
00:17:52,510 --> 00:17:55,840
So we need a way to make this dot answers,

338
00:17:55,840 --> 00:17:57,570
equal to this array.

339
00:17:57,570 --> 00:18:00,080
And so that's why we used to call method here,

340
00:18:00,080 --> 00:18:03,540
so that we could manually set the disk keyword,

341
00:18:03,540 --> 00:18:05,160
to a new object,

342
00:18:05,160 --> 00:18:08,653
which as the answers property has that new array.

343
00:18:10,090 --> 00:18:12,590
And now let's just try it with the other one here.

344
00:18:17,689 --> 00:18:20,447
And,

345
00:18:20,447 --> 00:18:23,240
and we can do the same without the string,

346
00:18:23,240 --> 00:18:25,853
and then it will just lock the array itself.

347
00:18:27,430 --> 00:18:30,730
And yeah, that works just fine.

348
00:18:30,730 --> 00:18:32,210
Great.

349
00:18:32,210 --> 00:18:36,520
Now, what we did here, it's not really a real scenario,

350
00:18:36,520 --> 00:18:39,500
but it's still good for us to use these concepts,

351
00:18:39,500 --> 00:18:41,020
in some different ways,

352
00:18:41,020 --> 00:18:43,930
to really get used to how all of these concepts,

353
00:18:43,930 --> 00:18:44,993
work together.

