This lesson I'm going to be adding in some global variables so that we can track the user's progress
as well as track the sequence that's being initiated by the computer that the player has to match.
So that will give us two sequences and give us the ability to compare those two sequences to see if
the player got the sequence right.
And in this case, we're going to need to set up some global variables.
So setting up and we're going to call one game clicks.
So this will be an array that the player can use or the game can use to store all of the clickable array
of colors.
And next, let's set up another one.
So this is user clicks and another blank array.
And we're going to be populating these as the user and as the game makes the sequences that we need
to follow.
We also want to set one up where we'll call it in play and set that to false.
So this will give us the ability to enable and disable the gameplay.
And one more where we've got our plate number, so this is how many colors we're going to show.
So the more color, the more the player gets them right.
We're going to increase this number.
So the more colors they're going to have to follow to move to the next part of the game.
So it's going to keep getting harder and harder, essentially.
So now, instead of the having the button.
Just go works, we're going to check to see if the inplay is false, because we don't want the player
to be able to restart.
We're going to check to see if the inplay is false and if the inplay is false.
We're going to run the function player and that's going to essentially set up our player area.
So setting up that function player, we're going to first take the button object.
So this is the start button here and we're going to play a property of disabled to it and set that value
to true.
So that will disable the ability to keep pressing that start button.
So they're not going to be able to press the start button anymore after this is launched.
And I'm also going to take these two arrays and I'm going to make sure that there's nothing in them.
So it's cleaning out.
So essentially it's going to launch a new game sequence and give the player the ability to create their
user sequence.
So let's try that out.
So when we hit start, we can only hit at one time and then it's disabled.
So ready to start building out the sequences and the next thing that we need to do is we need to run
the sequence, create the sequence that the player has to follow.
So let's set up a function for that so we can call it run sequence and we don't need anything else within
that function.
And the going down here, I'm actually going to move up this event.
Listener So they're both together.
And now let's create a function that will run the sequence and we don't need to pass any arguments in
there because that number that we're going to be going by is already a global variable.
So this play is a global value.
Let's go down to where we were tracking the clicks, where we've got that checked answer.
And now that we've got the inplay, we need to check to make sure that the game is in place.
Otherwise, we're not going to allow clicks on those elements.
So we make sure that it is in play.
And if it is in play, then we can get that target as well as we can output into the console and we
can take user clicks into the array or value into the array and taking the element.
So the same one that we're outputting and just outputting that might color into the user clicks and
we can now also console log out the user.
And before we try that out, let's put the in sequence.
So set in play and we're going to set and play to true.
So when you hit start.
So let's make this bigger.
So we hit start right now.
You can click on it.
It's not adding anything in when we hit start that we can see that we're actually adding in and we're
building out that sequence and you can see that's built out into the array.
So coming up next, we need to generate a sequence as well from the computer and as well we need to
light up these squares as we're clicking them.
So the next lesson I'm going to show you how we can light up these squares to indicate that they've
been clicked.
So that's still to come in the upcoming lesson.