In the earlier lessons, we built out a way to run different sequences, we can start at two items within
the sequence, go in, refresh our game, and it's always a good idea to try out your game and make
sure that it is functioning as needed.
So we go we have press start button.
We clicked the start button and we matched two items, building out an array that we're using for the
computer array.
And now it's up to the player to match that array by clicking the different values of the boxes.
So if we were to click blue and green, then we've built out that same array.
So we've got that colors and we've got the values within that same order.
Unfortunately, we can still keep clicking and continue to build out our array.
So let's take care of that in this lesson where we're going to put a stop to the having the user or
given the user the ability to continuously click and we're going to end the game at some point.
So going into where we're checking answer.
And this is the ideal spot to add that in, because this is where the user is taking an action and we
want to stop the user's ability from taking that action once the user clicks length, matches the game
length.
So go ahead and add that condition in.
And this is all happening within the inplay function.
So we're going to do our check and we've got the two arrays.
So we've got our user clicks length.
And each array, of course, has its own length and we're checking to see if the game CLECs length.
So if they are equal, then this is where we're going to end the game because we know that they're matching
in length and we're going to take the inplay variable and set it to false.
So boolean to false and we're going to create a new function that's going to end the game.
And so going in here function.
And this is where we can create our end game function.
And right now we'll just console logout game over, go out and test everything, make sure that it's
working as intended.
So now what's happening is when we start, we're going to see two colors blink.
The objective as the user has to kick the same two colors and we see that both those colors clicked.
So it was blue and green.
But in this case, I'll click to a click blue and green and we see that we can't click anymore.
The game is not allowing us to add to that array.
So this is where we've got our game over.
Function needs to be firing off and we see that the game over did, in fact fire off and get invoked.
So we are ready to move on to the next step where these two match in length.
We ended the gameplay and we've got our game over function and that's where we can take care of any
of the game functionality that we need to handle.
We've got our button value and we have button disabled.
So what we want to do is enable it so we do false.
That's going to enable that button.
So that's going to allow the player to start again and start that next sequence.
So we've got button disabled, so we enable the button and we also need to add in a check to see if
it was correct.
So let's take that value and we're going to add in the value of user clicks.
So from that function using to string.
So this is JavaScript method allowing us to transform an array into a string.
We're also going to take our game CLECs array and transform that into string as well so that we have
essentially two strings that we're comparing against each other.
And if the strings do match, then our play num increases by one.
And if they don't match, then essentially they didn't get it correct and over here will console log.
Correct.
So one more time, let's go ahead and try that out.
So refresh hit start.
We see it went green, blue.
We go green, blue.
We see that it was correct.
Try that one more time.
So start.
So it was blue.
Green.
Let's this time we're going to do it wrong.
So we got incorrect.
So that's working.
And you want to find out more about how to string works.
Mozilla Developer Network.
Once again, we've got some great examples here of how to string works.
And we can see that this is a way to turn a math value into a string, a hex string.
So we run that, we get E six.
So we get a hex value within the string.
And there's some more examples of how that works down below within the examples area where we're turning
a number into a string, a decimal point into a string.
And there's a bunch of examples here, how we're turning hexes into strings.
So go ahead and try that out for yourself, turn your arrays into strings, and then you can compare
them to see if the user got the correct answer or not.
And coming up, we're going to do some.
More tweaks and adjustments to the gameplay to make sure that it is functioning as expected and needed.