1
00:00:00,900 --> 00:00:07,500
In this lesson, we're going to add in the ability to keep track and have a score as well as be able

2
00:00:07,500 --> 00:00:08,760
to place bets.

3
00:00:09,030 --> 00:00:11,980
So we do have the elements set up on the page.

4
00:00:12,000 --> 00:00:14,520
We have a cash value for the user.

5
00:00:14,760 --> 00:00:20,130
And that means that we're going to go over to the I.T. where we're setting up the global variables and

6
00:00:20,130 --> 00:00:23,190
we'll set up some values contained within the game.

7
00:00:23,610 --> 00:00:26,050
We'll start the player off with cash.

8
00:00:26,460 --> 00:00:31,980
So whatever we want to stop, start them off with, start them off with 100, and then we will also

9
00:00:32,040 --> 00:00:37,920
need a variable value for a game that so we can start the game that off at zero.

10
00:00:38,130 --> 00:00:42,420
And then once we've updated the score, we need to update the cash.

11
00:00:42,690 --> 00:00:49,620
So creating a function that's going to update the cash and I'll just do that right below the iron I.T.

12
00:00:49,770 --> 00:00:50,250
function.

13
00:00:50,490 --> 00:00:52,330
And that one was update cash.

14
00:00:52,770 --> 00:00:58,380
And what this one will do is this will update whatever the cash value is that the player has available

15
00:00:58,380 --> 00:00:58,710
to them.

16
00:00:58,950 --> 00:01:01,350
And we're also going to set up a few other placeholders.

17
00:01:02,010 --> 00:01:08,040
So we'll have another function which will lock the wager and whatever value is being placed in there.

18
00:01:08,280 --> 00:01:16,050
So it will either enable or disable the input bet and set disabled to either true or false.

19
00:01:16,320 --> 00:01:19,290
So depending on whatever is passed into luck wager.

20
00:01:19,650 --> 00:01:26,220
And this will allow us to either enable or disable the ability to make additional bets, because once

21
00:01:26,220 --> 00:01:30,630
the game is in play, we don't want any additional that's being placed.

22
00:01:31,050 --> 00:01:36,240
So we're just going to be able to toggle that with just the one function, passing that information

23
00:01:36,240 --> 00:01:37,900
in to the lock.

24
00:01:38,160 --> 00:01:38,700
Wager.

25
00:01:39,270 --> 00:01:44,210
And we also want to have another function that can set the bet.

26
00:01:44,700 --> 00:01:47,490
And this is going to be whatever the bet is.

27
00:01:47,730 --> 00:01:54,060
It's going to lock the wager and allow us to continue with the gameplay and will once again communicate

28
00:01:54,090 --> 00:01:58,740
to the user within the status of text content.

29
00:01:59,310 --> 00:02:01,920
And we'll let the user know how much they bet.

30
00:02:02,510 --> 00:02:03,600
So you bet.

31
00:02:03,900 --> 00:02:07,260
And this value is going to be coming from the game.

32
00:02:07,610 --> 00:02:14,580
But we're going to update the game bet every time the user presses the bet amount and locking it in.

33
00:02:15,000 --> 00:02:21,930
So we're taking the game cash and we're equaling it to whatever the value of game cash is, minus the

34
00:02:21,990 --> 00:02:22,850
game that.

35
00:02:23,190 --> 00:02:29,970
So once we do the bet, we want to update the values that are contained within there and taking the

36
00:02:30,030 --> 00:02:33,750
game player cash object.

37
00:02:34,140 --> 00:02:36,630
And we're going to update the text content in there.

38
00:02:37,110 --> 00:02:43,450
And that will just say the player cache and whatever dollars the player has left with player cash.

39
00:02:44,070 --> 00:02:45,360
So game cash.

40
00:02:45,870 --> 00:02:47,760
And we also want to lock.

41
00:02:49,000 --> 00:02:49,840
The wager.

42
00:02:49,930 --> 00:02:51,680
So we're setting Laucke wager to trip.

43
00:02:51,820 --> 00:02:57,130
So the setting of the bet is going to be done when the BET amount button is pressed.

44
00:02:57,590 --> 00:03:01,180
So that means that we need to go down to where we had the buttons.

45
00:03:01,500 --> 00:03:09,190
We're enabling all the click buttons and take game that button objects out of that Lessner of click

46
00:03:09,760 --> 00:03:10,270
to it.

47
00:03:10,780 --> 00:03:17,860
And every time it's clicked, that means that we run the set, that function which locks in that that

48
00:03:18,130 --> 00:03:20,680
amount into the gameplay.

49
00:03:20,920 --> 00:03:25,300
And we also want to have a ability to update the value.

50
00:03:25,570 --> 00:03:33,160
So let's take game input that object at an event listener and the eventless so that we're listening

51
00:03:33,160 --> 00:03:34,330
for is change.

52
00:03:34,600 --> 00:03:40,990
So whenever anyone updates this value, we want the value that's contained within the cache to update

53
00:03:41,020 --> 00:03:43,450
and change and where we created the function for it.

54
00:03:43,780 --> 00:03:51,850
So the update cache can run, update cache can run, and that will visually update the cache as the

55
00:03:51,850 --> 00:03:55,810
players updating this and not until they pass the BET amount.

56
00:03:56,110 --> 00:03:58,840
Will that actually update from the players cache.

57
00:03:58,930 --> 00:03:59,980
So let's update.

58
00:04:00,250 --> 00:04:03,610
Let's add in that function for the update of cash.

59
00:04:03,820 --> 00:04:09,520
And first, we need to make sure that the input bet is real number.

60
00:04:09,520 --> 00:04:12,100
So we don't want someone typing in some characters.

61
00:04:12,610 --> 00:04:17,470
And this is text and a number field, but they still can type in some characters.

62
00:04:17,980 --> 00:04:20,110
So we want to make sure that that's avoided.

63
00:04:20,230 --> 00:04:29,920
So within the console log, we're going to make sure that it's not a number and game input, but value.

64
00:04:30,520 --> 00:04:32,170
And one more bracket there.

65
00:04:32,410 --> 00:04:36,040
So we can still copy and paste into it, even though it's a number field.

66
00:04:36,370 --> 00:04:37,630
And why do that amount?

67
00:04:37,870 --> 00:04:39,450
Let's refresh false.

68
00:04:39,730 --> 00:04:40,880
So everything is still okay.

69
00:04:40,930 --> 00:04:43,570
So this is a numeric value that we're using.

70
00:04:43,840 --> 00:04:45,220
And this is again, the number of fields.

71
00:04:45,220 --> 00:04:47,530
So most of the time this should be okay.

72
00:04:47,800 --> 00:04:53,620
But it's always good to have the checks to make sure that that input field is getting the value that

73
00:04:53,620 --> 00:04:54,370
you're expecting.

74
00:04:55,060 --> 00:04:58,010
So we'll make sure that it's returning back false.

75
00:04:58,150 --> 00:05:07,240
And if it's returning back, true or the game input, that value length is less than one.

76
00:05:07,570 --> 00:05:10,450
Then we're going to set that value to be zero.

77
00:05:10,810 --> 00:05:15,550
So I'll update the game, input that value to be zero.

78
00:05:15,760 --> 00:05:21,280
So if there's no value in there and we click off of it, it's gonna go back to zero.

79
00:05:21,460 --> 00:05:24,310
So that way we always have a value that we're working with.

80
00:05:24,580 --> 00:05:26,620
That's contained within the input field.

81
00:05:26,830 --> 00:05:34,210
And also, we're gonna check to see if input that value is greater than game cache.

82
00:05:34,540 --> 00:05:37,060
So we don't want someone betting more money than they have.

83
00:05:37,150 --> 00:05:40,150
So taking the game input that value.

84
00:05:40,210 --> 00:05:44,680
So if it's greater than whatever the cash is that's available, then we're going to is going to set

85
00:05:44,680 --> 00:05:46,000
it to whatever the cash value.

86
00:05:46,390 --> 00:05:48,220
So let's try that and save.

87
00:05:48,790 --> 00:05:52,060
So we can put in five thousand five hundred and fifty five.

88
00:05:52,300 --> 00:05:56,470
And when I press zero and if I did forget a period there.

89
00:05:56,910 --> 00:05:58,120
So let's try that one more time.

90
00:05:58,360 --> 00:06:00,790
So every time I click off of it, we'll see what happens.

91
00:06:00,790 --> 00:06:03,990
It brings it back to whatever my max cash value is.

92
00:06:04,060 --> 00:06:07,870
These are all fail safes that we need to incorporate.

93
00:06:07,960 --> 00:06:14,860
And we need to think of as we're developing the game just to make sure that the content is working as

94
00:06:14,860 --> 00:06:15,490
expected.

95
00:06:15,760 --> 00:06:17,380
So input that value.

96
00:06:17,500 --> 00:06:20,110
So this is going to be the global that object.

97
00:06:20,410 --> 00:06:23,470
And this is the same one that we're using when we're setting the bet.

98
00:06:23,800 --> 00:06:29,200
So using the global object and it's deleting that, subtracting the best value.

99
00:06:29,650 --> 00:06:39,250
And lastly, we need to update the player cache with text content and player cache dollars and the amount

100
00:06:39,250 --> 00:06:41,920
of money that the player has in cash.

101
00:06:42,190 --> 00:06:45,820
And this is just going to be dynamic at the time as the user's playing it.

102
00:06:46,030 --> 00:06:48,460
So it doesn't mean that they're actually committing that value.

103
00:06:48,670 --> 00:06:49,900
So game safe.

104
00:06:50,680 --> 00:06:55,750
So now whenever we increment this, you can see that the player caches adjusting according.

105
00:06:56,070 --> 00:07:01,510
If we put on a super large number player cache will go to zero and whatever value was within the player

106
00:07:01,510 --> 00:07:03,520
cache is gonna be available for betting.

107
00:07:03,700 --> 00:07:09,310
So coming up next, we're going to play through and we're going to update the bat values as the player

108
00:07:09,310 --> 00:07:10,240
at the dealer wins.

109
00:07:10,450 --> 00:07:13,260
So it update the cache that's available for the player to play.
