1
00:00:00,810 --> 00:00:01,600
Welcome back.

2
00:00:01,620 --> 00:00:07,950
Now that we've output the card information, we need to check to see which one is the high card and

3
00:00:07,950 --> 00:00:12,360
if there's any equal cards that we need to do a play, there's a few things that we need to add in and

4
00:00:12,360 --> 00:00:14,540
we can do this within the make cards function.

5
00:00:14,550 --> 00:00:19,920
So we're going to set up a variable and object in order to contain the current winner.

6
00:00:20,130 --> 00:00:26,280
And as we loop through the players, we can check who has the highest card and update this value.

7
00:00:26,790 --> 00:00:29,120
So we've got a value for high.

8
00:00:29,160 --> 00:00:31,850
And right now we're just going to set it as default null.

9
00:00:32,550 --> 00:00:34,630
And we also have the player.

10
00:00:34,770 --> 00:00:38,340
So this is going to indicate which player is the current winner.

11
00:00:38,700 --> 00:00:45,390
So as we loop through all of the players, we can check to see which one is currently ahead and in the

12
00:00:45,390 --> 00:00:45,630
lead.

13
00:00:46,050 --> 00:00:51,310
So after we make a selection of the card, this is where we can check and we can apply our condition.

14
00:00:51,720 --> 00:00:58,980
So taking that current winner object that we just created, we can check to see if the high card there

15
00:00:58,980 --> 00:01:01,500
is equal to the card value.

16
00:01:01,650 --> 00:01:04,860
And if it is, that means that we go into a play off.

17
00:01:04,860 --> 00:01:06,510
So we'll console log tie.

18
00:01:06,660 --> 00:01:12,210
And we're also going to set up another condition that's going to check to see if there's currently no

19
00:01:12,210 --> 00:01:21,120
current winner or so, no current winner, high value or there's no current winner high and the card

20
00:01:21,120 --> 00:01:24,470
value is greater than the current winner high.

21
00:01:24,510 --> 00:01:32,640
And if that's the case, then we need to set that current winner high value to the current card value.

22
00:01:32,670 --> 00:01:36,710
And that also means that we can set the current winner player.

23
00:01:36,930 --> 00:01:40,620
So this is going to be the player that is going to be the current high.

24
00:01:40,740 --> 00:01:45,480
And we get that from X as we're looping through all of the variables.

25
00:01:45,480 --> 00:01:49,350
And we also want to track the card that is the current winner.

26
00:01:49,830 --> 00:01:53,310
So we're going to equal that to whatever the value of card is.

27
00:01:53,460 --> 00:02:00,300
So as we loop through, we're going to know which is the current winner and then afterwards we can output

28
00:02:00,300 --> 00:02:01,880
whoever the current winner is.

29
00:02:01,950 --> 00:02:07,500
So doing that within the function, so do that outside of the loop and let's output that current winner

30
00:02:07,500 --> 00:02:08,060
object.

31
00:02:08,070 --> 00:02:15,150
So let's try that one more time hit start and you can see that we output that object and we get player

32
00:02:15,150 --> 00:02:16,570
one as the winner.

33
00:02:16,980 --> 00:02:22,020
So they ended up with clubs, a queen of clubs, which had a value of eleven.

34
00:02:22,380 --> 00:02:24,480
And you can see that the player won.

35
00:02:24,510 --> 00:02:26,340
So this is within the array format.

36
00:02:26,460 --> 00:02:32,230
So that means that it's actually player two, but within the array, it's got an index value of one.

37
00:02:32,250 --> 00:02:33,500
We'll try that one more time.

38
00:02:33,810 --> 00:02:36,660
So this is how we can detect who the winners are.

39
00:02:36,900 --> 00:02:43,530
And in this case, we do have a problem because the current winner, it means that there's a tie game.

40
00:02:43,540 --> 00:02:48,330
So we see that the current high is equal to the card value.

41
00:02:48,510 --> 00:02:55,470
So we also know that there is a tie that's been thrown and both of them are actually going to be within

42
00:02:55,470 --> 00:02:55,950
the tie.

43
00:02:55,950 --> 00:03:02,280
So we need to determine between which one of these the current winner is going to be for the winner.

44
00:03:02,400 --> 00:03:04,160
We're going to have to run a playoff.

45
00:03:04,170 --> 00:03:07,370
So let's set up an object to hold that information.

46
00:03:07,590 --> 00:03:09,030
And this can be an array.

47
00:03:09,180 --> 00:03:14,430
And whatever we do have this type of playoff situation, we're going to add items into the array.

48
00:03:14,850 --> 00:03:15,930
So checking to see.

49
00:03:15,930 --> 00:03:23,430
And if the current high is equal to the card value, that means that let's overrate this tie and this

50
00:03:23,430 --> 00:03:25,670
is where we've got our tied game function.

51
00:03:25,980 --> 00:03:33,120
So first we're going to check to see if the playoff array length is equal to zero.

52
00:03:33,480 --> 00:03:38,220
And if it is, that means that we haven't deposited anything to that playoff array yet.

53
00:03:38,400 --> 00:03:41,310
And that means that we need to push two values in.

54
00:03:41,310 --> 00:03:43,680
We need to push the current value.

55
00:03:43,950 --> 00:03:49,200
So we're going to playoff push and using the array method.

56
00:03:50,250 --> 00:03:55,950
We're going to push a new item into the rain, this is going to be an object so we can push in a value

57
00:03:55,950 --> 00:03:56,710
for player.

58
00:03:56,880 --> 00:04:00,330
And this is going to be whatever the current winner player is.

59
00:04:00,930 --> 00:04:06,080
That way, we're depositing the information into our current array.

60
00:04:06,630 --> 00:04:10,230
And also we're going to need to know what card is in play.

61
00:04:10,590 --> 00:04:11,970
So current winner.

62
00:04:12,950 --> 00:04:19,280
And card information, so we get those two pieces of information, which, of course we are setting

63
00:04:19,280 --> 00:04:23,150
down here, and we're checking against the current winner high.

64
00:04:23,360 --> 00:04:26,090
So we pushed that into the playoff object.

65
00:04:26,420 --> 00:04:30,510
And then we also need to push the new value in as well.

66
00:04:30,830 --> 00:04:35,380
So before we set the current value, we need to push the new value in.

67
00:04:35,780 --> 00:04:39,650
So pushing it in and the same object information.

68
00:04:40,430 --> 00:04:47,660
What we need, we need to get the value of X, which is of course the current player, and then the

69
00:04:47,660 --> 00:04:50,360
card is just the value of the card object.

70
00:04:50,510 --> 00:04:54,890
And then it will also get added into the array as we loop through.

71
00:04:54,900 --> 00:05:01,040
So we're going to know that at this point we do need to have a playoff session in order to account for

72
00:05:01,040 --> 00:05:03,650
any of the playoff conditions.

73
00:05:03,650 --> 00:05:05,290
So we need to run that function for now.

74
00:05:05,300 --> 00:05:10,430
We're going to add in a placeholder for the playoff content to rebuild that functionality afterwards,

75
00:05:10,590 --> 00:05:12,500
essentially the way the playoff is going to work.

76
00:05:12,620 --> 00:05:19,670
So if we have a situation like this where we've got two cards that are both equal and it's got two players

77
00:05:19,670 --> 00:05:24,500
that have those cards, and we can also accommodate if we have more, because, again, we are building

78
00:05:24,500 --> 00:05:29,880
an array so we can constantly push in more players and their cards into that array.

79
00:05:30,080 --> 00:05:35,360
So what we want to do is we want to have a function in order for the playoff to flip the next card,

80
00:05:35,360 --> 00:05:38,710
the next card, the next card until we actually return back a winner.

81
00:05:38,720 --> 00:05:43,760
So we need to run a function that's going to flip the cards and check to see who the winner of those

82
00:05:43,760 --> 00:05:49,910
cards is and also build an array of all of the cards that have been flipped over so we can add them

83
00:05:49,910 --> 00:05:50,210
in.

84
00:05:50,210 --> 00:05:55,000
And the winner of all of this playoff is actually going to get all of the card information.

85
00:05:55,400 --> 00:05:59,150
So now that's fairly complex and we are going to handle that in the upcoming lesson.

86
00:05:59,420 --> 00:06:03,110
So coming up next, what we want to do is want to make an update.

87
00:06:03,110 --> 00:06:09,530
So we want to detect who the winner is and we want to run the update of the functions.

88
00:06:09,540 --> 00:06:13,390
So adding in all of these cards to whoever the winner is.

89
00:06:13,430 --> 00:06:15,500
So they're going to get all of the cards that they beat.

90
00:06:16,110 --> 00:06:17,120
So that's coming up next.
