Welcome back.
Now that we've output the card information, we need to check to see which one is the high card and
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
we can do this within the make cards function.
So we're going to set up a variable and object in order to contain the current winner.
And as we loop through the players, we can check who has the highest card and update this value.
So we've got a value for high.
And right now we're just going to set it as default null.
And we also have the player.
So this is going to indicate which player is the current winner.
So as we loop through all of the players, we can check to see which one is currently ahead and in the
lead.
So after we make a selection of the card, this is where we can check and we can apply our condition.
So taking that current winner object that we just created, we can check to see if the high card there
is equal to the card value.
And if it is, that means that we go into a play off.
So we'll console log tie.
And we're also going to set up another condition that's going to check to see if there's currently no
current winner or so, no current winner, high value or there's no current winner high and the card
value is greater than the current winner high.
And if that's the case, then we need to set that current winner high value to the current card value.
And that also means that we can set the current winner player.
So this is going to be the player that is going to be the current high.
And we get that from X as we're looping through all of the variables.
And we also want to track the card that is the current winner.
So we're going to equal that to whatever the value of card is.
So as we loop through, we're going to know which is the current winner and then afterwards we can output
whoever the current winner is.
So doing that within the function, so do that outside of the loop and let's output that current winner
object.
So let's try that one more time hit start and you can see that we output that object and we get player
one as the winner.
So they ended up with clubs, a queen of clubs, which had a value of eleven.
And you can see that the player won.
So this is within the array format.
So that means that it's actually player two, but within the array, it's got an index value of one.
We'll try that one more time.
So this is how we can detect who the winners are.
And in this case, we do have a problem because the current winner, it means that there's a tie game.
So we see that the current high is equal to the card value.
So we also know that there is a tie that's been thrown and both of them are actually going to be within
the tie.
So we need to determine between which one of these the current winner is going to be for the winner.
We're going to have to run a playoff.
So let's set up an object to hold that information.
And this can be an array.
And whatever we do have this type of playoff situation, we're going to add items into the array.
So checking to see.
And if the current high is equal to the card value, that means that let's overrate this tie and this
is where we've got our tied game function.
So first we're going to check to see if the playoff array length is equal to zero.
And if it is, that means that we haven't deposited anything to that playoff array yet.
And that means that we need to push two values in.
We need to push the current value.
So we're going to playoff push and using the array method.
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
for player.
And this is going to be whatever the current winner player is.
That way, we're depositing the information into our current array.
And also we're going to need to know what card is in play.
So current winner.
And card information, so we get those two pieces of information, which, of course we are setting
down here, and we're checking against the current winner high.
So we pushed that into the playoff object.
And then we also need to push the new value in as well.
So before we set the current value, we need to push the new value in.
So pushing it in and the same object information.
What we need, we need to get the value of X, which is of course the current player, and then the
card is just the value of the card object.
And then it will also get added into the array as we loop through.
So we're going to know that at this point we do need to have a playoff session in order to account for
any of the playoff conditions.
So we need to run that function for now.
We're going to add in a placeholder for the playoff content to rebuild that functionality afterwards,
essentially the way the playoff is going to work.
So if we have a situation like this where we've got two cards that are both equal and it's got two players
that have those cards, and we can also accommodate if we have more, because, again, we are building
an array so we can constantly push in more players and their cards into that array.
So what we want to do is we want to have a function in order for the playoff to flip the next card,
the next card, the next card until we actually return back a winner.
So we need to run a function that's going to flip the cards and check to see who the winner of those
cards is and also build an array of all of the cards that have been flipped over so we can add them
in.
And the winner of all of this playoff is actually going to get all of the card information.
So now that's fairly complex and we are going to handle that in the upcoming lesson.
So coming up next, what we want to do is want to make an update.
So we want to detect who the winner is and we want to run the update of the functions.
So adding in all of these cards to whoever the winner is.
So they're going to get all of the cards that they beat.
So that's coming up next.