Now that we've created our basic structure, we're ready to create the game we need to add in an event
listener to the button object.
So adding an event listener and the event that we want to listen for is a click.
And once it gets clicked, let's create a function so anonymous function where we've got all of our
start functionality and we're really going to have that one button in the game.
So that's going to be the one that's going to have the ability to start the game.
So looking through our code, we've got an array with my words and we've got a number of different words
that are in that array.
So to make this a little bit more interesting, we want a random order, sort this array.
So taking the my words array, we want to sort that within a random order.
If we use JavaScript sort, that gives us the ability to sort the elements in place.
And you're going to see that once I sort that, if I console log out that my words array.
So every time I click start, you're going to see that we're outputting the my words array and it's
always now in alphabetical order.
So it's taken the C, the J and the L..
So although it did sort it outside of the order that we currently have, it's not exactly what we want
it.
So we won't have a callback function in here that we can return back and manipulate the sort order.
So returning back those items that we're sorting, we can multiply it by by negative five and then do
a math random.
So this is going to give us a random value that's either going to be positive or negative.
And when we return that value, you can see that now what's happening is a random sorting our array.
So this is the quick and easy way to create a random sorting of your array.
Using the sought method and adding in a function that's going to return back either a negative or a
positive, and that's going to influence the sort order of the elements within your car.
So that's going to influence the sort order of the items within your array.
So now that we've picked out and we have random sorting, we have our starting word.
So whatever the first one is going to be within the array, that's the word that we're going to use
and that's the one that we're going to output to the player.
So taking that word, we can just call it the word.
And now we've got a randomly sorted array.
We can use the shift method.
And what shift does is it removes the first element from the array and returns that element.
And what it's going to do is essentially into the word.
It's going to place one of the values from the array.
So now we can only press it three times because once we press it the fourth time, we only have three
items in the array.
So we come up with an undefined and as you can see, it's going to be a different sort order every time,
and it's just simply removing them out of the array.
So that gives us the ability to have a really random order of all of the content.
And if you've got a lot of words in there, it's going to make it really interesting for the players.
So go ahead and add that into your project.
Try out the sort method with the return in order to randomly sort in place your array values and then
also select out that first item and pull that out of your my words array.
So coming up next, we're going to build out our board.
And that's going to be the interesting part because we're actually going to see something within our
browser other than a start button.
So that's still to come, the next lesson.