This is the randomise array lesson where we need to randomize one of the items from the array.
So we need to pick one of these words and then we also need to scramble the letters in the word and
I'll show you how to do all of this.
Within this lesson, we're going to turn these strings into arrays and then we're going to randomize
the order of the items in the array.
So we see that we've got our inplay and then this is where we need to build out our word.
So we'll call it create word and create a function for that.
So the function and we'll consult log this out for now and then we're going to update that to output
to the inner HTML.
So create a function that can create the word.
And then using JavaScript, we're going to select one of the elements at random.
So selecting random index.
Now we need to use math random in order to generate a random number and we're going to multiply it by
the length of what our array is.
So that's the array that we've got all of our content and we had called it Mairie.
So selecting that array and we know that all arrays will have a value there of length.
Let's do random index and see what's going to be output now.
So we will refresh it.
You see that we've got a two and we've got a bunch of decimal bunch of places there after that.
So three and a whole bunch of digits after that, like Dorte, digits after that.
And if you're familiar with JavaScript and math, you know that if you use math flaw, that will get
rid of all that excess.
So basically, it will strip away all of the decimal and all the excess characters, leaving us with
a number from zero all the way up to.
And in this case, we've got five items as a length.
So it's going to be zero to four.
We're going to be returning back of value.
If you want to select random value from one to five, then you would have to add a plus one to this
function.
So now we've got a random number anywhere from zero to four and we see zero.
We saw four earlier.
We saw one, two, and eventually we would get three as well.
So we're getting our random index and that allows us to select a random value from the my array.
So let's call it temp word.
And this is the word that we're going to be using using the mihiri, adding in the random index value
that we've just generated.
We're going to selecting one of these array words at random.
And I'll show you that this way.
We're selecting one of those words at random and we can output that into the console.
So refresh start and we see that.
We see we're getting a random word.
So refresh start.
Now we got document and we're getting an undefined there.
And that means that we're not returning anything.
So let's go ahead and return that temp word value so that we can also see that within the other console
message.
So now we got course on that one start again, of course, on this one and so on.
So we're generating one of those words at random.
And it just so happened that we got course three times in a row.
But as you can see, we can get other values as well.
So now we've got a random word.
And next, we need to scramble the words, the letters in this word, and we're going to use JavaScript
function in order to do that.
And we'll call it function random array to be passed in.
When we use JavaScript, we can turn any string into an array using split.
So if we take temp word and if we split this using the JavaScript split method and then this is two
double quotes there you can see that we're going to be splitting that out and it's going to be turning
it into an array.
So now our JavaScript word is in an array and that means that we can use the random array function,
which we're going to set up in the upcoming lesson to reorganize the items in the array.
And you can see that all the time.
It turns it into an array.
So coming up next, I'll show you how to do that.
So for this lesson, go ahead and build the random selection from the array and then output that random
string value, random item from the array, then split it into an array that we can use and work with
in the upcoming lesson.
So go ahead and add that into your application.