1
00:00:02,070 --> 00:00:03,990
Now the last example I wanna dive

2
00:00:03,990 --> 00:00:08,270
in is this statistics example here.

3
00:00:08,270 --> 00:00:10,600
And here, we will use a while loop.

4
00:00:10,600 --> 00:00:13,260
I can already say that it's probably not

5
00:00:13,260 --> 00:00:15,580
too surprising, given that we haven't

6
00:00:15,580 --> 00:00:18,320
used a while loop in any other example.

7
00:00:18,320 --> 00:00:21,620
And the goal here will be to get that entered number

8
00:00:21,620 --> 00:00:24,470
and upon a click, we wanna roll the dice

9
00:00:24,470 --> 00:00:28,520
in JavaScript and roll it as often as needed

10
00:00:28,520 --> 00:00:32,220
to the derive or to roll that target number,

11
00:00:32,220 --> 00:00:35,350
which therefore must be between one and six.

12
00:00:35,350 --> 00:00:38,340
And we then wanna output all the dice rolls we had

13
00:00:38,340 --> 00:00:41,340
in a list and also output sum summary

14
00:00:41,340 --> 00:00:44,083
as statistics down there in this sentence.

15
00:00:45,200 --> 00:00:47,050
So for that here, I have my

16
00:00:48,130 --> 00:00:52,810
statistics roll the dice example.

17
00:00:52,810 --> 00:00:57,120
And here we all start again by getting access to the button.

18
00:00:57,120 --> 00:01:00,700
The rollDiceButtonElement here.

19
00:01:00,700 --> 00:01:03,370
That sounds like a fitting name and justice

20
00:01:03,370 --> 00:01:07,500
before I'll get access to the button with query selector.

21
00:01:07,500 --> 00:01:11,930
As I did it before by utilizing the section ID,

22
00:01:11,930 --> 00:01:15,250
which in this case is statistics.

23
00:01:15,250 --> 00:01:17,580
So you would stat ID here to get

24
00:01:17,580 --> 00:01:20,383
access to this button like that.

25
00:01:22,410 --> 00:01:27,219
Then, I actually add a little helper function,

26
00:01:27,219 --> 00:01:32,219
rollDice, which will roll the dice for me.

27
00:01:32,450 --> 00:01:34,370
And then the main function that should

28
00:01:34,370 --> 00:01:36,620
be executed when the button is clicked.

29
00:01:36,620 --> 00:01:39,530
We don't need two separate functions,

30
00:01:39,530 --> 00:01:42,050
but I'm doing it here to have a clear separation

31
00:01:42,050 --> 00:01:45,240
between those random number code, which I'll put

32
00:01:45,240 --> 00:01:48,270
into this rollDice function and the main code

33
00:01:48,270 --> 00:01:51,820
for then outputting the roll of list items.

34
00:01:51,820 --> 00:01:55,240
And so on in this main function that is connected

35
00:01:55,240 --> 00:01:57,693
to a click listener on the button.

36
00:01:58,660 --> 00:02:02,387
And I'll name this function, deriveNumberOfDiceRolls.

37
00:02:04,520 --> 00:02:08,360
Like that, and then connect those roll dice

38
00:02:08,360 --> 00:02:11,590
button element with addEventListener

39
00:02:11,590 --> 00:02:16,590
as before upon a click and then here point

40
00:02:17,020 --> 00:02:20,023
at derive number of dice rolls.

41
00:02:21,810 --> 00:02:26,030
Now I'll start here with derive number of dice rolls.

42
00:02:26,030 --> 00:02:29,890
In there, I need to get access to that input

43
00:02:31,100 --> 00:02:34,930
element here and conveniently this has an ID,

44
00:02:34,930 --> 00:02:37,130
which we can use because that will

45
00:02:37,130 --> 00:02:39,450
be the number which we wanna roll.

46
00:02:39,450 --> 00:02:42,167
And therefore we cannot get access to this element and store

47
00:02:42,167 --> 00:02:45,730
it in the constant, which could be named

48
00:02:45,730 --> 00:02:50,730
targetNumberElement or targetNumberInputElement,

49
00:02:54,710 --> 00:02:57,870
by using document get element by ID

50
00:02:57,870 --> 00:03:01,693
and using that ID was added to this input element.

51
00:03:03,915 --> 00:03:07,520
And then we got the entered number,

52
00:03:07,520 --> 00:03:10,660
which is a constant name I already used before.

53
00:03:10,660 --> 00:03:14,030
In an earlier example, I did use this here

54
00:03:14,030 --> 00:03:17,240
and calculate some already, but since I created

55
00:03:17,240 --> 00:03:19,790
it inside of a function, it was exclusive

56
00:03:19,790 --> 00:03:22,260
to this function and I can therefore create another

57
00:03:22,260 --> 00:03:24,440
constant with the same name in a different

58
00:03:24,440 --> 00:03:27,527
function and entered number here, of course is

59
00:03:27,527 --> 00:03:30,633
targetNumberInputElement.value.

60
00:03:31,510 --> 00:03:35,700
Now, I also wanna get access to this unordered list,

61
00:03:35,700 --> 00:03:39,110
which I then use for outputting my dice rolls.

62
00:03:39,110 --> 00:03:41,200
And that has an idea as well.

63
00:03:41,200 --> 00:03:43,930
So here I'll then create a never constant

64
00:03:43,930 --> 00:03:46,240
before I get my entered number, actually

65
00:03:46,240 --> 00:03:48,710
though the order would not matter here.

66
00:03:48,710 --> 00:03:51,730
I just like to group that together since I will have two

67
00:03:51,730 --> 00:03:54,630
constants that select elements and hence someone

68
00:03:54,630 --> 00:03:57,160
to kind of keep them together for readability

69
00:03:57,160 --> 00:04:02,003
purposes and I'll name this the diceRollsListElement here,

70
00:04:03,660 --> 00:04:08,660
where I also use document get element by ID and use that ID.

71
00:04:08,790 --> 00:04:13,200
Then we have the next step and extract the entered number.

72
00:04:13,200 --> 00:04:16,720
And I will also reach out to dice rolls list element,

73
00:04:16,720 --> 00:04:20,310
and set inner HTML to an empty string to, again,

74
00:04:20,310 --> 00:04:25,040
clear any existing list items we might have in there.

75
00:04:25,040 --> 00:04:27,180
We don't have any items initially,

76
00:04:27,180 --> 00:04:29,630
but once we clicked the roll the dice button,

77
00:04:29,630 --> 00:04:32,170
the first time we will have items.

78
00:04:32,170 --> 00:04:34,120
And I always wanna clear those.

79
00:04:34,120 --> 00:04:37,440
If we click that button again, adjust as we cleared

80
00:04:37,440 --> 00:04:39,733
said user data upon a button click.

81
00:04:41,650 --> 00:04:44,120
Now we can continue.

82
00:04:44,120 --> 00:04:45,560
We have that entered number,

83
00:04:45,560 --> 00:04:48,010
which is the number we wanna roll.

84
00:04:48,010 --> 00:04:51,230
So now as a next step here,

85
00:04:51,230 --> 00:04:54,720
I wanna add a while loop where we keep

86
00:04:54,720 --> 00:04:59,533
on rolling numbers until we rolled this entered number.

87
00:05:00,560 --> 00:05:03,390
And a for this I'll add a new variable.

88
00:05:03,390 --> 00:05:06,020
And that is now a variable and not a constant

89
00:05:06,020 --> 00:05:09,630
because it will receive new values

90
00:05:09,630 --> 00:05:11,170
and dead variable could be named,

91
00:05:11,170 --> 00:05:16,170
hasRolledTargetNumber, which is false initially.

92
00:05:17,120 --> 00:05:19,880
It's a Boolean value, which I store in here.

93
00:05:19,880 --> 00:05:23,140
Hence I have dis variable naming here,

94
00:05:23,140 --> 00:05:25,460
which answers a question basically,

95
00:05:25,460 --> 00:05:30,460
which is how you typically do name your Boolean variables.

96
00:05:30,550 --> 00:05:33,300
And that's false initially because we haven't rolled our

97
00:05:33,300 --> 00:05:36,910
target number yet, but we wanna set it to true inside

98
00:05:36,910 --> 00:05:39,403
of the dwell loop once we did roll it.

99
00:05:40,370 --> 00:05:44,380
So here I will keep on rolling as long as we have not.

100
00:05:44,380 --> 00:05:47,980
Hence the exclamation mark rolled the target number

101
00:05:49,130 --> 00:05:50,980
and then here between curly braces,

102
00:05:50,980 --> 00:05:53,400
we have the actual code for this loop

103
00:05:53,400 --> 00:05:56,460
and that's where we now wanna roll a number.

104
00:05:56,460 --> 00:05:59,880
So here I will execute this rollDice function,

105
00:05:59,880 --> 00:06:01,910
even though it's not doing anything yet,

106
00:06:01,910 --> 00:06:06,463
we'll add the logic soon, I'll execute rollDice.

107
00:06:06,463 --> 00:06:09,550
And I simply expect that this function will

108
00:06:09,550 --> 00:06:13,260
return a random number between one and six.

109
00:06:13,260 --> 00:06:17,770
So here I then have my rolled number and that's a constant

110
00:06:17,770 --> 00:06:22,350
because it will be recreated for every while loop execution.

111
00:06:22,350 --> 00:06:25,620
So it's not reassigned, but it's a brand new variable,

112
00:06:25,620 --> 00:06:28,190
a brand new constant that will be created

113
00:06:28,190 --> 00:06:31,020
for every while loop iteration.

114
00:06:31,020 --> 00:06:34,583
And it will hold that rolled number between one and six.

115
00:06:35,760 --> 00:06:40,760
And now we can check if rolled number is equal to entered

116
00:06:42,470 --> 00:06:46,280
number, and I'm using two equal signs instead

117
00:06:46,280 --> 00:06:50,350
of free equal signs here because entered number

118
00:06:50,350 --> 00:06:53,490
when retrieved from the value property

119
00:06:53,490 --> 00:06:57,160
of an input element will always be a string.

120
00:06:57,160 --> 00:07:00,130
It might be a number that was entered by the user,

121
00:07:00,130 --> 00:07:02,380
but it will be a pipe string.

122
00:07:02,380 --> 00:07:05,960
That's just how HTML and JavaScript works.

123
00:07:05,960 --> 00:07:08,750
When you get the value of an input field,

124
00:07:08,750 --> 00:07:13,160
it's always a string, even if the input is of pipe number.

125
00:07:13,160 --> 00:07:15,660
And even if the user did enter a number,

126
00:07:15,660 --> 00:07:17,780
JavaScript does not care about that.

127
00:07:17,780 --> 00:07:21,840
You always get a string and therefore this entered number,

128
00:07:21,840 --> 00:07:26,010
even though it is a number of value will be a pipe string.

129
00:07:26,010 --> 00:07:30,010
And hence we could either convert it to a number this could

130
00:07:30,010 --> 00:07:34,090
easily be done by adding a plus here in front of it.

131
00:07:34,090 --> 00:07:36,450
That's a quick way of converting a string

132
00:07:36,450 --> 00:07:40,450
to a number in JavaScript, or we don't do this.

133
00:07:40,450 --> 00:07:43,610
And instead we just use the double equal sign comparison

134
00:07:43,610 --> 00:07:48,130
operator here to compare a number value,

135
00:07:48,130 --> 00:07:50,730
which roll dice we'll return eventually

136
00:07:50,730 --> 00:07:55,723
to a string value and check for value equality only.

137
00:07:56,770 --> 00:07:58,930
And inside of this if statement,

138
00:07:58,930 --> 00:08:02,620
we can then set hasRolledTargetNumber

139
00:08:02,620 --> 00:08:06,543
to true if that here yields true.

140
00:08:08,010 --> 00:08:09,840
Now this is one way of doing it,

141
00:08:09,840 --> 00:08:12,740
but it's actually a bit too long on the otherhand

142
00:08:12,740 --> 00:08:16,390
it is hopefully pretty easy to understand.

143
00:08:16,390 --> 00:08:20,480
Nonetheless, I'll comment it out because if you write

144
00:08:20,480 --> 00:08:24,300
a if statement to then store a Boolean value,

145
00:08:24,300 --> 00:08:26,630
based on the result of this, if condition

146
00:08:26,630 --> 00:08:30,220
in another variable, then you can shorten this

147
00:08:30,220 --> 00:08:33,309
and you can just write hasRolledTargetNumber

148
00:08:33,309 --> 00:08:36,883
equal to the result of this comparison.

149
00:08:38,140 --> 00:08:42,130
Because keep in mind these comparison operators yield a

150
00:08:42,130 --> 00:08:45,670
Boolean value, true or false.

151
00:08:45,670 --> 00:08:48,260
And if that's what we wanna store in a variable,

152
00:08:48,260 --> 00:08:50,200
we don't need the extra if check.

153
00:08:50,200 --> 00:08:52,700
We can just store the result of this Boolean

154
00:08:52,700 --> 00:08:56,530
comparison in this variable here.

155
00:08:56,530 --> 00:08:58,700
It's not something we did up to this point

156
00:08:58,700 --> 00:09:00,720
in the course, but it is something which

157
00:09:00,720 --> 00:09:03,710
is also quite common to do in JavaScript.

158
00:09:03,710 --> 00:09:07,150
If you have a variable or any place in your code

159
00:09:07,150 --> 00:09:09,330
that needs a Boolean value, that should

160
00:09:09,330 --> 00:09:11,750
be the result of some comparison.

161
00:09:11,750 --> 00:09:13,360
You don't need the if check.

162
00:09:13,360 --> 00:09:15,260
You can just store the comparison

163
00:09:15,260 --> 00:09:18,450
result itself in the variable.

164
00:09:18,450 --> 00:09:20,460
So this will yield true or false.

165
00:09:20,460 --> 00:09:22,970
And hence we store true or false

166
00:09:22,970 --> 00:09:26,093
in that has rolled target number variable.

167
00:09:27,300 --> 00:09:31,757
And if this should be true, this will no longer yield

168
00:09:31,757 --> 00:09:34,010
true, because we have the negation operator

169
00:09:34,010 --> 00:09:36,110
and we would leave the while loop

170
00:09:36,110 --> 00:09:39,700
once we rolled our target number therefore.

171
00:09:39,700 --> 00:09:42,400
And hence now after does while loop,

172
00:09:42,400 --> 00:09:46,470
we can output some summary statistics.

173
00:09:46,470 --> 00:09:51,470
We can say how many rolls it took us to roll the target

174
00:09:52,230 --> 00:09:57,230
number for this we'll need access to these spans here,

175
00:09:57,420 --> 00:10:00,540
where we do output our summary data.

176
00:10:00,540 --> 00:10:02,780
And we also need to keep track

177
00:10:02,780 --> 00:10:04,663
of the number of rolls we have.

178
00:10:05,780 --> 00:10:08,950
Now I'll first of all, get access to these spans here.

179
00:10:08,950 --> 00:10:12,740
And the first span has an idea of output, total rolls,

180
00:10:12,740 --> 00:10:15,140
so I'll create a constant here,

181
00:10:15,140 --> 00:10:20,140
output total rolls element where I use

182
00:10:20,200 --> 00:10:23,813
document get element by ID and use that ID.

183
00:10:25,030 --> 00:10:27,330
And then we have the second span

184
00:10:27,330 --> 00:10:30,410
where we output that target number.

185
00:10:30,410 --> 00:10:34,410
And this span has an ID of output target number.

186
00:10:34,410 --> 00:10:36,673
So here we can now use this and store

187
00:10:36,673 --> 00:10:39,350
this in a constant as well.

188
00:10:39,350 --> 00:10:43,970
The output target number element that could

189
00:10:43,970 --> 00:10:46,940
be a name we use and then use document

190
00:10:46,940 --> 00:10:51,063
get element by ID output, target number.

191
00:10:52,640 --> 00:10:54,900
Now for output target number element,

192
00:10:54,900 --> 00:10:57,920
we can already set the text content.

193
00:10:57,920 --> 00:11:02,860
So here we can set text content equal to the enteredNumber.

194
00:11:02,860 --> 00:11:05,830
So the entered number, which we extract up here,

195
00:11:05,830 --> 00:11:07,370
because we just wanna repeat

196
00:11:07,370 --> 00:11:08,800
that entered number down there.

197
00:11:08,800 --> 00:11:12,700
So that's easy, now for the number of rolls,

198
00:11:12,700 --> 00:11:16,030
we will have to keep track of those rolls.

199
00:11:16,030 --> 00:11:19,870
And for that, I'll create another helper variable here,

200
00:11:19,870 --> 00:11:24,870
which will name numberOfRolls, and which is 0 initially.

201
00:11:25,930 --> 00:11:29,403
And it is created before we entered that while loop,

202
00:11:30,270 --> 00:11:34,850
because inside of that, while loop, I wanna change it.

203
00:11:34,850 --> 00:11:39,430
There I want to set numberOfRolls equal

204
00:11:39,430 --> 00:11:44,430
to numberOfRolls + 1, I wanna increment it by 1.

205
00:11:45,810 --> 00:11:47,460
And of course, if that's the goal we can

206
00:11:47,460 --> 00:11:49,670
always adjust used is short-hand.

207
00:11:49,670 --> 00:11:53,280
We learned about with the plus plus operator,

208
00:11:53,280 --> 00:11:54,690
which is the same.

209
00:11:54,690 --> 00:11:57,490
This will increment number of rolls by one

210
00:11:57,490 --> 00:12:00,170
and store that new value in that variable

211
00:12:01,070 --> 00:12:02,760
and therefore a number of rolls in the end,

212
00:12:02,760 --> 00:12:05,080
will it be the number of rolls that took us.

213
00:12:05,080 --> 00:12:10,080
And hence we can set output total rolls element text,

214
00:12:10,260 --> 00:12:15,260
content, equal to number of rolls like this.

215
00:12:15,810 --> 00:12:18,680
With that, we're outputting this, but we still don't

216
00:12:18,680 --> 00:12:21,100
create a list item for every roll.

217
00:12:21,100 --> 00:12:24,220
And of course we're not rolling the dice at all.

218
00:12:24,220 --> 00:12:26,000
We'll do that as a last step.

219
00:12:26,000 --> 00:12:29,370
First of all, let's create a list item for every roll

220
00:12:29,370 --> 00:12:33,840
where we log that roll to the screen, basically.

221
00:12:33,840 --> 00:12:38,500
And for that maybe here off after number of rolls,

222
00:12:38,500 --> 00:12:43,500
I wanna create a new roll list element

223
00:12:44,290 --> 00:12:47,840
with document create element, and we create a list

224
00:12:47,840 --> 00:12:52,470
item here as we did it a couple of minutes before as well.

225
00:12:52,470 --> 00:12:57,470
And then on this new roll list element or list item element,

226
00:12:57,680 --> 00:13:00,730
if you wanna be super precise here with our naming

227
00:13:00,730 --> 00:13:03,410
on that element, which be created,

228
00:13:03,410 --> 00:13:07,650
I wanna set the text content here to again,

229
00:13:07,650 --> 00:13:09,870
a little bit of a more complex string.

230
00:13:09,870 --> 00:13:12,150
So again, I will create a helper constant

231
00:13:12,150 --> 00:13:17,150
for that the output text constant, which says roll.

232
00:13:18,120 --> 00:13:21,230
And then I wanna have to number of that roll,

233
00:13:21,230 --> 00:13:24,550
which is number of rolls here.

234
00:13:24,550 --> 00:13:26,940
Since I'm doing that after incrementing number

235
00:13:26,940 --> 00:13:30,440
of rolls that will already be the correct number.

236
00:13:30,440 --> 00:13:33,630
And then I wanna have a semi colon and a white space.

237
00:13:33,630 --> 00:13:36,340
Hence I concatenate that string

238
00:13:36,340 --> 00:13:39,463
and then output the rolled number.

239
00:13:40,860 --> 00:13:44,740
And now we can set this output text here as a value

240
00:13:44,740 --> 00:13:49,250
for the text content on the new roll list item element.

241
00:13:49,250 --> 00:13:52,860
And we can then use this list here,

242
00:13:52,860 --> 00:13:57,460
the dice rolls list element to append this item.

243
00:13:57,460 --> 00:13:59,790
So on that dice rolls list element,

244
00:13:59,790 --> 00:14:03,530
I call append and append the new roll list,

245
00:14:03,530 --> 00:14:05,303
item element like this.

246
00:14:06,160 --> 00:14:10,450
With that, we should be outputting that roll result.

247
00:14:10,450 --> 00:14:12,060
Now we just need to make sure

248
00:14:12,060 --> 00:14:15,030
that we do actually roll a random number.

249
00:14:15,030 --> 00:14:18,200
So we need to work on that rollDice function.

250
00:14:18,200 --> 00:14:21,320
And here in this function, we will utilize some

251
00:14:21,320 --> 00:14:24,010
built in functionality, JavaScript offers

252
00:14:24,010 --> 00:14:26,440
to us when it comes to working with random

253
00:14:26,440 --> 00:14:29,740
numbers and with numbers in general.

254
00:14:29,740 --> 00:14:32,190
We wanna return the value of course,

255
00:14:32,190 --> 00:14:34,300
and that value, which I wanna return

256
00:14:34,300 --> 00:14:35,217
here is basically a random number.

257
00:14:35,217 --> 00:14:40,217
For this we have Math.random just as we

258
00:14:41,450 --> 00:14:44,460
have console.log for logging something.

259
00:14:44,460 --> 00:14:48,000
We have a globally available math object,

260
00:14:48,000 --> 00:14:49,500
which is built into the browser.

261
00:14:49,500 --> 00:14:52,760
So to say, which has random method,

262
00:14:52,760 --> 00:14:54,420
which returns a random number

263
00:14:54,420 --> 00:14:58,960
between zero and one, zero is included.

264
00:14:58,960 --> 00:15:01,720
One is excluded and it returns

265
00:15:01,720 --> 00:15:04,930
any floating point number in between basically.

266
00:15:04,930 --> 00:15:07,793
So it returns value is like this.

267
00:15:10,070 --> 00:15:11,820
Now here, we don't want a number

268
00:15:11,820 --> 00:15:15,323
between zero and one though, but between one and six.

269
00:15:16,180 --> 00:15:21,180
Therefore we'll start by multiplying Math.random with six.

270
00:15:21,500 --> 00:15:24,863
Now we have a random number between zero and six.

271
00:15:26,310 --> 00:15:31,310
Now we don't want all these floating point numbers though.

272
00:15:31,620 --> 00:15:33,810
We want integers only.

273
00:15:33,810 --> 00:15:35,870
And for that, we have another built in

274
00:15:35,870 --> 00:15:40,870
method on this math object and that's the floor method,

275
00:15:40,890 --> 00:15:45,600
which we can wrap around this result, which we derived here.

276
00:15:45,600 --> 00:15:49,670
So we pass the result of calling Math.random

277
00:15:49,670 --> 00:15:53,800
and multiplying it with six as a parameter value

278
00:15:53,800 --> 00:15:58,410
to Math.floor and Math.floor will

279
00:15:58,410 --> 00:16:01,060
simply round dead value down.

280
00:16:01,060 --> 00:16:04,150
It will round it down to the nearest integer.

281
00:16:04,150 --> 00:16:07,370
It cuts any decimal numbers basically.

282
00:16:07,370 --> 00:16:12,370
So if we have 5.64 that would be rounded down to just five.

283
00:16:13,440 --> 00:16:15,940
That's what Math.floor does.

284
00:16:15,940 --> 00:16:20,670
So let me just make this clear here what Math.floor does.

285
00:16:20,670 --> 00:16:22,610
That's what it does.

286
00:16:22,610 --> 00:16:24,050
Now, that's still not all though,

287
00:16:24,050 --> 00:16:25,660
because that will give us a number

288
00:16:25,660 --> 00:16:30,083
between zero and six, six excluded.

289
00:16:30,920 --> 00:16:33,040
And therefore what we need to do as a last step

290
00:16:33,040 --> 00:16:36,180
is we need to add one because now we have

291
00:16:36,180 --> 00:16:38,290
a random number between one and six.

292
00:16:38,290 --> 00:16:41,120
Since we simply add one to our random number

293
00:16:41,120 --> 00:16:43,950
between zero and five, which we got effectively

294
00:16:43,950 --> 00:16:46,320
with just discoed and this code.

295
00:16:46,320 --> 00:16:48,660
And therefor now, we have a function that yields

296
00:16:48,660 --> 00:16:51,613
a random number between one and six.

297
00:16:53,220 --> 00:16:55,450
And now that should be all, was quite

298
00:16:55,450 --> 00:16:57,690
a lot of work, but it should be all.

299
00:16:57,690 --> 00:17:01,970
If we now is save that and I enter four,

300
00:17:01,970 --> 00:17:05,619
then if I click this button, I see some output

301
00:17:05,619 --> 00:17:07,890
and that output output will differ every

302
00:17:07,890 --> 00:17:09,869
time I click this button and you'll see

303
00:17:09,869 --> 00:17:13,792
how many rolls it's took to roll a four.

304
00:17:15,710 --> 00:17:20,060
So that's now this example implemented as well.

305
00:17:20,060 --> 00:17:25,060
And what we see here is a great use case for a while loop,

306
00:17:25,680 --> 00:17:29,900
where we keep on executing some code until a certain

307
00:17:29,900 --> 00:17:32,623
condition is not met anymore.

