In this lesson, we're going to add in the ability to keep track and have a score as well as be able
to place bets.
So we do have the elements set up on the page.
We have a cash value for the user.
And that means that we're going to go over to the I.T. where we're setting up the global variables and
we'll set up some values contained within the game.
We'll start the player off with cash.
So whatever we want to stop, start them off with, start them off with 100, and then we will also
need a variable value for a game that so we can start the game that off at zero.
And then once we've updated the score, we need to update the cash.
So creating a function that's going to update the cash and I'll just do that right below the iron I.T.
function.
And that one was update cash.
And what this one will do is this will update whatever the cash value is that the player has available
to them.
And we're also going to set up a few other placeholders.
So we'll have another function which will lock the wager and whatever value is being placed in there.
So it will either enable or disable the input bet and set disabled to either true or false.
So depending on whatever is passed into luck wager.
And this will allow us to either enable or disable the ability to make additional bets, because once
the game is in play, we don't want any additional that's being placed.
So we're just going to be able to toggle that with just the one function, passing that information
in to the lock.
Wager.
And we also want to have another function that can set the bet.
And this is going to be whatever the bet is.
It's going to lock the wager and allow us to continue with the gameplay and will once again communicate
to the user within the status of text content.
And we'll let the user know how much they bet.
So you bet.
And this value is going to be coming from the game.
But we're going to update the game bet every time the user presses the bet amount and locking it in.
So we're taking the game cash and we're equaling it to whatever the value of game cash is, minus the
game that.
So once we do the bet, we want to update the values that are contained within there and taking the
game player cash object.
And we're going to update the text content in there.
And that will just say the player cache and whatever dollars the player has left with player cash.
So game cash.
And we also want to lock.
The wager.
So we're setting Laucke wager to trip.
So the setting of the bet is going to be done when the BET amount button is pressed.
So that means that we need to go down to where we had the buttons.
We're enabling all the click buttons and take game that button objects out of that Lessner of click
to it.
And every time it's clicked, that means that we run the set, that function which locks in that that
amount into the gameplay.
And we also want to have a ability to update the value.
So let's take game input that object at an event listener and the eventless so that we're listening
for is change.
So whenever anyone updates this value, we want the value that's contained within the cache to update
and change and where we created the function for it.
So the update cache can run, update cache can run, and that will visually update the cache as the
players updating this and not until they pass the BET amount.
Will that actually update from the players cache.
So let's update.
Let's add in that function for the update of cash.
And first, we need to make sure that the input bet is real number.
So we don't want someone typing in some characters.
And this is text and a number field, but they still can type in some characters.
So we want to make sure that that's avoided.
So within the console log, we're going to make sure that it's not a number and game input, but value.
And one more bracket there.
So we can still copy and paste into it, even though it's a number field.
And why do that amount?
Let's refresh false.
So everything is still okay.
So this is a numeric value that we're using.
And this is again, the number of fields.
So most of the time this should be okay.
But it's always good to have the checks to make sure that that input field is getting the value that
you're expecting.
So we'll make sure that it's returning back false.
And if it's returning back, true or the game input, that value length is less than one.
Then we're going to set that value to be zero.
So I'll update the game, input that value to be zero.
So if there's no value in there and we click off of it, it's gonna go back to zero.
So that way we always have a value that we're working with.
That's contained within the input field.
And also, we're gonna check to see if input that value is greater than game cache.
So we don't want someone betting more money than they have.
So taking the game input that value.
So if it's greater than whatever the cash is that's available, then we're going to is going to set
it to whatever the cash value.
So let's try that and save.
So we can put in five thousand five hundred and fifty five.
And when I press zero and if I did forget a period there.
So let's try that one more time.
So every time I click off of it, we'll see what happens.
It brings it back to whatever my max cash value is.
These are all fail safes that we need to incorporate.
And we need to think of as we're developing the game just to make sure that the content is working as
expected.
So input that value.
So this is going to be the global that object.
And this is the same one that we're using when we're setting the bet.
So using the global object and it's deleting that, subtracting the best value.
And lastly, we need to update the player cache with text content and player cache dollars and the amount
of money that the player has in cash.
And this is just going to be dynamic at the time as the user's playing it.
So it doesn't mean that they're actually committing that value.
So game safe.
So now whenever we increment this, you can see that the player caches adjusting according.
If we put on a super large number player cache will go to zero and whatever value was within the player
cache is gonna be available for betting.
So coming up next, we're going to play through and we're going to update the bat values as the player
at the dealer wins.
So it update the cache that's available for the player to play.