In the previous lesson, we saw how we can start building out that random sequence where when we hit
the start button, we see that one of the squares lights up.
And now in this lesson, I'm going to show you how you can continue to build out that sequence to run
and light up all of the squares.
And the secret is we're going to use another set time out.
So this time out is going to be sitting within the other set time out.
So setting up a function that's going to run on this time out and this time out is going to initiate
another sequence.
So we're going to run that same function with the value of no inside of itself.
And that will continue to loop through that sequence.
And we're only going to break out of running the sequence when we're returning this value whenever the
value of NUM is less than zero.
So let's try that out and open that up in our browser, go back out and refresh it.
And when we hit start, we see that it runs that one item and then we can start building out our own
sequence.
Now, let's update this value to five and see what happens.
So refresh hit start.
So we've got one, two, three, four, five colors.
We built out our array, the computer array, using the five colors, using the run sequence.
So we're ready to move on to the next step where we can let the player match that sequence that was
built out and check to see if the player actually matched the sequence and move them up a level and
continue to play the gameplay.
Letting a function run within itself is called recursion in JavaScript, and this is a great way to
practice and get more comfortable with looping through functions and using recursion in JavaScript.
So go ahead and try it out for yourself.