OK, ladies and gentlemen, let's continue working on our dice game, so what we actually now need to
do, we already we are rolling the dice, right?
So we now need to calculate the result and store it in one of our areas that we put it here.
Player scores.
Now, I'm just going to show you the where is it in this query selector.
If I Konza log
the live player, it will always be zero.
Right.
Just going to inspect it.
And it will always be zero, so we need to change that one in order to play around who, who who will
be active and who will be not active player.
Right.
So we have a couple of things here to do.
This is one of the most important lectures and let's do it.
OK, now I'm just going to leave that one here and I'm going to say document, not get Elliman by these.
And I just want to target live there and I'm going to say, plus active.
Live player right now, active player, so I'm going to say style display to block.
OK, so what we are doing here, obviously, that I want, when it's zero, this player to go green
and this player just like that in when it's one, I want to change it.
This player to be green, this one to not be green.
So if I change it right now, it will be green and it will stay green because we never we never change
this guy here.
So how we can achieve this.
Remember, we can do this with evil statement.
We can check if the live player is zero.
And why is this happening?
I didn't explain.
So we get the element by the live Samus here like this.
But instead of manually putting these dash zero dash one, I just use that live player variable that
we set to zero at the beginning.
This is our initial value now.
OK, so what we can do is actually we can check in for the life player like this with the ternary operator,
remember.
So I'm going to say live player.
It is equal to zero.
I got to change a live player.
If that is true, I'm going to change the life player to one else.
I'm going to change the life player back to zero.
So if it's one, it's going to be zero.
If it's zero, it's going to become one.
Now we can cause a lot of the live player
and you will see their keep changing.
So I'm going to refresh.
So it's going to be zero, then one, then it's going to be one zero.
Then it's going to zero in one Y because we're printing this one here.
Right.
So we are actually now able to change it, but we're not able is do we need to set the other one to
display none.
And that is what we need to do now.
So I'm just going to grab this one.
I'm going to put it here because now the live players change.
If it was zero, it will be a one now.
And I want that to become display none right here.
Yeah, that's pretty much it.
What I want to change.
Let's check.
Let's check it out.
Nope, nope.
One Danisco go to this one, that is to go to this one again, then it's go to this one again.
So now I hope you understand I'm just going to close this deal.
So what I did first is always zero because we initial when we start is going to be zero.
And that is our goal.
I want to start here with this guy with Blair, one, I don't want to start backwards.
And now we set that the display block and it magically appears this guy here, right then I change it.
I'm checking if one player is zero, then, yeah, change it to one.
Otherwise, if next cycle when this life player will be one, then it will not be true.
Right.
And we go here, it will set it to zero.
So we just swapping.
Right.
So you can do this.
I challenge you to do it with if else statement.
So again, it is this one, it's working now.
We need to find a way how we can store these variables.
I store these dice numbers for the player and put the other player right.
So whenever all at once, I just everything that's here to be for this player.
Right.
This is the green one.
The next one is green.
I want this tree to go there.
So how we can do this?
Well, we will use that actual help say we actual
player scores area.
Right.
I'm just going to copy it so I don't want to make a mistake.
So what we will do now after this one is block.
I'm going to check it here, play score and I'm going to say of the live player and I'm going to say
plus equal to dice, right.
Because dice contain that random number and actual dice is going to be this one.
Right.
So I can console like console lock the player scores for live player.
Remember when I say live player it will start with zero zero player scores of zero and we will expand
or we will add the value of dice.
Then we're going to log in and next time it will be player scores one and we're going to pen that dice
for him.
I hope I'm clear about that one.
OK, let's check.
Check if this is working on a refresh.
So here it is five.
I do have five for this player.
So when they roll it on the other player, I'm going to have two.
Right.
I'm going to roll it again.
I have five plus four.
It's nine.
When I'm going to roll it again, it will be three plus two, OK, because this is not visibly very
good.
So when I'm going to do I'm just going to change it something for you guys.
So I'm just going to change.
This comes a lot and I'm going to say score for player and I'm going to upend the player as well.
Live life later and I'm going to say plus.
Plus again.
OK, and that should do its job, this life, Blair is not correct, OK, now score for player zero
is actually this guy here, street score four.
Player two is actually four.
Player one is actually two.
Right.
This is a play that's a little bit awkward because I name to start with zero zero, right?
Yeah, you can change it here.
Player zero in player one if you want.
So player zero will be big, but it's not logical to be zero right now.
Five before player zero was three and now plus five, it is equal eight.
So this is actually, ladies and gentlemen, working as it shoot.
Now, the interesting part is we see we are twenty three and we still can rule.
Oh, this is not good because we are over our limit.
So how we can set a limit here.
OK, before this I just going to cut it from here and I'm going to see if players scores of zero is
less than twenty so you can make it to 100.
There's a man I just don't want to make it long and player scores of one is less than twenty.
So I just want to check it both so means that must both of them player zero in player one to have scored
less than.
And I'm going to basted that back here to have less than twenty else pounds a lot.
We have a winner, winner, winner.
Chicken dinner, ladies and gentlemen.
So I'm going to put it one five.
OK, I'm going to roll it.
So twenty.
The player won.
This player actually reached twenty and when I click next time I don't want to go here and calculate.
Yeah.
And plus this is working actually here.
We need to stop it.
But the winner is there.
We have a winner.
Right.
It's not going to do anything else.
It's not going to go inside this loop here.
It's not going to add to the result.
It's not going to do anything.
No, we have to have time.
So what we can do is actually make this little bit more spicy.
OK, so we need to upend the result that we have.
We already have the result, right.
So we need to append those result to the final score, that particular player.
So after this, after we are setting to none and again, to display block, what I'm going to say here
is that we need to pretty much document that query selector.
And what we need to select is I'm going to show you right now.
So we need to find final score.
Here it is.
So for the both of the players, I do have final score and that was fifty.
And I'm not going to do it manually.
Right.
So I'm going to say, OK, because we using the query selector and that was the idea over there.
Right.
So we're going to use the ID like that with the hash final score dash.
We're going to leave a dash, but we're going to continue with the live player because the last player
we know, it's changing and we're going to say tax content that will be equal to the player scorer Aare
that is holding the live player value.
Let's see if this is working or not.
Do we have this console lock still?
Yes.
So I'm just going to say one, if it's not working, OK, we need to fix it.
So we need to fix it.
And obviously this should not be here, should be somewhere here because after that we're changing the
player and we're doing a lot of things.
Now, I hope when I see for the player one, I will see updated version.
Right, two in two here.
So when I switch it to the other one, it's going to be for how cool is this?
The player is working seven five five.
Yeah.
OK, four plus one, four plus one is five.
Yeah.
I was thinking something is wrong but the calculation is working pretty much so I reached twenty the
player number to reach twenty and we have a winner.
Right.
It's not going to go anywhere, it's not going to add it actually it's going to roll but it's not going
to edit the values down.
So that is pretty much it now we can safely comment this one.
So what we have done this.
In this lecture, we just
change the life layer for find, which the life layer is, and we set the display block after that with
ternary operator, we switch to the other player and the other one turned to none.
Right after that.
What we did is that we add to each of the players, this is the area for each of the players, for the
zero and for the one we add that dice number from before and the beginning with.
If else, we are checking if they do not have more than 20, because if they do, obviously some of
them is a winner.
So I hope you understand if you don't, because I've done it step by step, issued probably by now.
Understand how this is the process is working, right.
So again, six to six plus four, is that right?
Here it is.
And that is pretty much done.
So this guy has twenty three and actually it's not going to allow me to go to the next guy.
We're going to say, OK, we have a dinner winner, sorry, not dinner because it's, it's probably
dinner time for me.
So thank you very much.
And I will see you in the next lecture.