Let's do a quick overview of the content and the game that we built out.
We had a little bit of styling that we added in.
We also added in some HTML so that the user has a play area and some content to interact with.
Then we selected the elements from the page that we needed to utilize as JavaScript objects so that
we can quickly access them, manipulate them and make updates to them.
And that's connecting it to the DOM object using document selector.
We had some variables that we needed to set up for the gameplay added in an event.
Lyster to the button and then this button.
So the first time it runs through this is basically our start sequence that we run through on the first
time.
So we're updating the interest to the button.
So changes to guess from start.
We were hiding and hiding the input field.
We were creating a word using our function to create a word.
And what all this was doing, this was just generating a random index value and then getting that random
index value, selecting an item from the array, using the index value and then returning that word
that we've just generated out.
We also so we generate the word randomly from the array and then we scramble that word.
And this was the interesting part of this section is that we created a way to randomize content in an
array.
And again, this is a very useful function.
So we loop through the array and we swapped.
So we moved through the array, the of length of that array, and we swapped items within the array.
So index values.
So we created a temp, one random index value.
And then what we did over here is this is just a swap.
And as you can see, we're taking I setting it to J and then taking J and setting it to AI and then
we're returning to a rate that we just created.
And that is all happening here within the random array.
And then once we return it back, it's still with an array format.
So we need to join it together to turn it back into a string.
Once we turn it into a string, we can output that scrambled word.
We'll get rid of the solution.
And then if we're allowing the player to make guesses, this is the guess value.
So it's just taking that value from the input field.
We're updating the score.
We can get rid of the console message and we're equaling or checking to see if the player got a correct
answer.
And if they did, then this is what we do for correct.
Essentially, we output the message of correct.
We set reset our new word generation function so that next time we click the button, it will be start
and we're going to go through the setup again.
So using the inplay as a boolean value, we update the value of the button once again to B start.
We output a message to the user so they know what happened and then we toggle that input field, so
we hide it so it's no longer available.
And if we got it wrong, then simply right now in the console, like we're putting guess again and here
we can actually output and we could say wrong and we still need to output the word again.
So we need to output whatever that scrambled word is.
So start and if I get it wrong, I get wrong and I still have the same word.
Or if you wanted to, you could randomize the order of the word if you wanted to.
So every time they get it wrong, we can switch the letters around.
So eventually that can be a little bit more interesting for the player.
So there's quite a few things that you can do to extend on this application.
Thanks again for taking this section and learning more about how you can apply randomness to arrays
and put it into a working application game.