There's going to be a fun lesson where we're gonna get into the game place, we're going to do some
calculations and conditions to check and ensure that there's progress within the game and allow the
player to move on to the next steps.
So once they deal, we want to enable the hit and stand.
But this is also dependent on what the card values are and what actions the player needs to be able
to take.
So we're going to add in a new function.
So under.
Deal.
And we can just call this update count.
We're not passing any parameters in there.
And this is where we're going to do the check and update of where the game progress is.
So update count.
And this function will run every time it's dealt and also serve as a way to kind of move things along.
So we want to actually pick up the score value that's available.
Within the player and the dealer.
So it's going to be an important part that we want to be able to track the score.
So let's create another function that will calculate the score.
So just call this function score.
We'll call it score.
And coming into update count, we want to be able to pick up the players, score and pass the game player
hand into the score.
So it's going to do a calculation of that array object.
And then also we want a value for dealer and using the same function that we're passing in the dealer
hand array values into there.
And then within score, we're going to pick up those values and then make use of them.
So essentially, this can be a hand that's being passed in.
We need to calculate out the value that's contained within the hand and then return back a number of
value for the user.
And I'll output the values of player and dealer.
So have to do some calculations here and return back the response.
So let's set up some default values and set them to zero.
And if it's an ace, because we're gonna have to account for possibility of multiple aces.
So depending on what the score and what the value is and loop through the hand array.
So for now, what we can do is console log out the value of hand.
So this is whatever is being passed in.
And then right now, we'll just return back.
A value of one.
So it's price deal.
And see what happens, a clear deal.
And we'll see that both of those hands get passed in.
And as you can see, it is an array.
So this particular one has Spade's rank value and as well.
King value.
And then we also get the other hand that gets Pastan.
So we see that this is going to be the dealer's hand.
And that's the player's hand surpassing in player's hand first.
And then the dealer's hand second.
And also, it compares to what we see on the screen as well.
So taking the hand array the loop through each one of the items that are contained within the hand.
And we can output it as card.
And then just console log out the value of whatever is contained within card.
So we have a deal.
We get each one of the cards as output there.
And that's going to loop through.
And this way we can update the total.
So we've got a running total of whatever's available within the particular hand that's been passed him.
And make sure that it is a number.
So we're going to use them.
No method to force it to be a numeric value.
And then we can also return back the total of one.
And also forcing total to be a number.
So we're turning back the counted values.
So the dealer has eleven.
And the player has 20.
So we're turning those back in.
There's a little bit more we're gonna have to do with score.
But for now, let's go back to the update count.
And we can update the count.
Values that are contained for each one of those.
So we can apply various conditions depending on what's being returned back.
So first, let's add in the count for the player.
So under the game player score.
Set the tax content.
So that's where we've got that Dasch there.
We're going to update it to whatever the value that's being returned back from.
And so we got a value of 13 there.
It looks like we have to apply a little bit of styling as well to going into our stylesheet.
I'm going to update a value for score, do display block and make the font size bigger.
And then also adjust the margin of 15 picks at the top and then zero at the bottom.
And that moved our default card.
So we need to make an adjustment for that as well.
So it looks but right now we're taking up a default spot there for score and we're outputting the players
score.
So we have to also go back and we have to enable the button.
And this is going to allow the player to have an additional action.
So if the player is under 21, then using that turn on and selecting the game button hit, we're going
to enable that.
And then we also want to turn on the game button stand so that the user has an option for moving the
game along.
And that's only if it's under 21.
And then also under game status, let's update the text content and say stand or take another card.
So it provides some instructions for the user on what their next course of action can be.
And there's more that we're going to have to do, more conditions we're gonna have to add in and we'll
do that in the upcoming lesson.
So now we've got the option to hit and stand.
So we've enabled those buttons and we can continue with the gameplay for the player.
So coming up, the second part of building the update count, as well as updating the score in order
to handle the game functionality.