The way that I usually make games is I try to anticipate what the next step is.
So we've got our starting point and we're starting and now we're presenting the player with a question
of whether it's higher or lower.
And we also need to build out the deck of cards and we also need to display the card for the player.
I also, before we begin this lesson, I want to go into style and update one of the styling values
of score, because right now the style is not in line, it's not in line block.
So I want to set that up, taking the class score.
Using the display property.
And display in line block, so that no longer goes onto a second row.
So it's nice and neat and compact in there, going back to index and for the drawing of the card, we
need to do a quick check to make sure that we have an existing deck.
So deck is a global variable that we set up in the earlier lesson.
It's an array and checking to see if this array has a length of greater than zero.
And if it does, then we run this block of code.
And if it doesn't, then we know we need to build a deck.
And that's where we can run a function that can say, make deck, return back, draw a card.
So after we make the deck, we're going to run, draw a card, and then this time the deck will have
a length and we can output that value of the card and return that one back to the player.
So for now, we'll just do our return card.
I'll set a default value for card.
So the way that this function is going to work, once we get to this value where it says my card invoking
the function called draw card going over to this function, we're going to look to see what the length
of decks.
And currently when we first start out the length of deck is nothing because we don't have anything in
that array yet.
So it's going to move on to the else.
It's going to go into the make deck function, invoke this function here or not make card.
So we need to have another one here for make deck.
And this is where we're going to build out our deck of cards.
Once it completes that, it's going to return draw a card, which is going to loop it back into this
function.
And then go through these conditions again, and the next time it goes through, once we have a deck,
we'll have a length for that deck.
So it's going to make deck.
And first of that, we want to do here is zero any content that might currently be in the deck.
And we don't have anything in there right now.
And this is going to be a series of loops.
So setting up our first loop, setting eye to zero, we're going to loop through while the value of
suits.
So suits is that array where we've got all of the suits is less than the value of suits length.
We're going to increment I by one as we loop through these values.
We need a loop inside of a loop so this loop we can set let G equals zero and we're going to loop through
G while G is less than ranks.
Length and then increment by one.
So what's happening here?
And actually, it doesn't matter.
You could do ranks on the outside, in suits on the inside.
It's going to still build out everything the same way.
So there's no difference between the order.
We're just looping through all of these values.
And we know that four in a deck of cards Hearts has all of the rank values.
Diamonds has all of the rank values, clubs and spades have all of the rank values.
And that makes up our deck of cards.
So that's why we need to do the two loops to loop through both of those arrays.
So each one of the suits gets assigned a rank value.
And as we're looping through, we're going to build out a card.
So the card is going to be an object.
And that as we loop through, we need to assign that object a suit value and we can get that from that
array that we're building out next.
We've got our rank and selecting our ranks value that's going to correspond with G.
And then we've got our card value and this can correspond with the value of G plus once we get a numeric
value for each card.
And you can assign also some additional values here.
And then lastly, what we're doing is we're taking that deck so that empty Decorah that we have globally
and we're pushing card into that deck.
And as we loop through, you're going to see that we're going to build out our deck of cards.
And then after we finish all of these loops, we're going to see that deck that built that the deck
that we built sitting in the console.
So let's try that it.
I'll make this bigger, we hit start and there's our deck of cards, so the first card here is the two
of hearts.
It's got a value of one.
Three of hearts, a value of two all the way down.
We've got our Jack has value of ten and Ace, which is our highest card, has a value of thirteen.
And that's how we're going to rank all of the cards higher, lower.
So aces are the highest card.
You could also do them, sort them that aces are the lowest card.
And that would just be a matter of sorting them and positioning them differently within the deck where
you could place the ace in the beginning if you wanted the ace to be worth one and so on.
So it does matter of how you want to stock your deck, the value of your deck, some games that aces
are the top, some games the aces are the bottom.
It's up to you how you want to set that up.
And that's basically how you build that deck of cards.
So go ahead and try it out for yourself.
You can try out with the making deck function first if you want, and see how the deck looks like.
Just invoked that function anywhere within your code or outside within your console and try it out and
make sure that you can build out the deck.
And then here you can apply that logic when we're drawing a card.
And coming up next, I'll show you how we can return a card value now that we have a deck of cards.
So that is all still yet to come.