Excellent work.
We're almost done now, of course, we just want to make it a bit harder for a user where the correct
answer is not going to be always at the end of our.
So I'll leave this for your reference.
That's why I'll come to the south and we'll create a new jury in this case.
I'm going to go with that and we'll say answers is equal to that.
Not so.
I'll spread out the incorrect answers.
And of course, what happens right now, I have the right by the name of answers, and there I have
the values coming from the incorrect answers.
And then once I have my answers, the way I would want to generate a random number every time I display
a question.
So we know that, of course, our questions are changing because our index is changing and that every
time we get a new question, I would want to generate that random number.
Now, I can also tell you that it might get a bit annoying where we'll have to get a new set of questions
every time we say something in the abstract.
So once I make some changes and if I want to see counsel, I will have to generate a new set of questions.
So that might get a bit annoying, but I think it is going to be easier for all of us to be on the same
page if I can log my values.
So let's create that random number.
So tempting index and that is going to be equal to the math.
Random now, math, random returns a random number between zero and zero point and ninety nine, not
including one.
But the thing is, I would want to generate a random number between zero and three y one because I know
that my answers already eventually is going to have four values and first index is going to be zero
and the last one will be three.
Now, in order to get that, I first only to invoke my random and then I need to multiply this by four.
But the thing is, I don't want three point six or whatever decimal value.
Instead, I always want to round it down.
So on here I will say math and then four and we pass in that math, round them by four.
And once we have this one, let's comes along the temp index and what we should get is the random values
between zero and three.
It's never going to be four, but it might be zero.
So it share it.
I will, I guess, navigate the bigger screen.
We just submit these rulers and then in the council notice now the value is three.
So once I click the next question now, the value for my random one is zero.
Then I have another zero, then I have zero, then I have zero and then I have one.
So even though technically this was random, it just came out that way where I had four zero zero.
But at least you can see that we are getting these random numbers.
So what is next?
Well, next, I would want to set up my logic and this is going to be the case where I'll type everything
up and then I'll go over what is happening.
So I'll check if the temp index is equal to three.
And if that is the case, I'm going to go with answers that push and I'm just going to add that correct
answer.
So if the index value is going to be three, similarly how I had previously, I'm just going to place
the correct answer at the end of my answers.
All right.
So I just go with push, which at the end of.
All right.
And I have the correct answer.
So that is going to be the case if the value is equal to three.
Now, if the value is not equal to three, if the value is equal to zero one or two, then we need to
do a little bit of work where first of all, I will push the current value that I have in the next to
the end of the array.
So that's why I go with answer that push and then I'm looking for that particular value.
So temp index and then move the correct one in that spot.
Again, let me type it out and then I'll go over it in greater detail.
So I look for temp index, whatever it is, and I'll set it equal to my correct answer.
So what is happening over here?
Well, the answer is not defined, so it should be answers, not Bush over here and the way it works.
We have answers here and I just add these incorrect answers.
So, of course, I have an array of three items.
Correct.
And they have indexes of zero, one and two.
Then I generate random number and that random number could be zero one, two or three.
So if the number is three, what does that?
Well, that means that technically there is no such index in disarray, correct, because this one will
always be three, it will always be three items.
So the last index will be true.
So if my random number is three, then the only thing I do is just add my correct answer at the end
of the day.
Similarly, like we had before.
But keep in mind that this is generated randomly.
In this case, we were always placing that correct answer at the end.
Not in here.
In here, only if the temp index is equal to three.
OK, hopefully that is clear.
And then if the random number is either zero, one or two, I take the index, whatever it is from my
error and add it to the end of.
All right.
So imagine my temp index is two.
I push to the end of array, the item that has the index of two hours ago.
It answers that portion.
And then I'm looking for that item that has the index off to.
So add it to the end of right.
And then in that spot I place the correct answer.
So hopefully that is clear.
If you need to do some login, please do so.
But in my case I will test it out.
So let me click on start and I'll try to cheat again.
But notice when I click on the last button, I can see that these answers are not correct, which is
really, really good.
That means that of course now we have a random powers.
So actually the user needs to know the right answer.
That is our application.
Hopefully everyone enjoyed it and I hope to see the next one.