1
00:00:00,550 --> 00:00:05,590
In the previous lesson, we saw how we can start building out that random sequence where when we hit

2
00:00:05,590 --> 00:00:09,340
the start button, we see that one of the squares lights up.

3
00:00:09,640 --> 00:00:14,530
And now in this lesson, I'm going to show you how you can continue to build out that sequence to run

4
00:00:14,530 --> 00:00:16,390
and light up all of the squares.

5
00:00:16,600 --> 00:00:19,860
And the secret is we're going to use another set time out.

6
00:00:20,050 --> 00:00:23,460
So this time out is going to be sitting within the other set time out.

7
00:00:23,770 --> 00:00:31,150
So setting up a function that's going to run on this time out and this time out is going to initiate

8
00:00:31,150 --> 00:00:32,380
another sequence.

9
00:00:32,630 --> 00:00:37,630
So we're going to run that same function with the value of no inside of itself.

10
00:00:38,870 --> 00:00:41,290
And that will continue to loop through that sequence.

11
00:00:41,590 --> 00:00:46,900
And we're only going to break out of running the sequence when we're returning this value whenever the

12
00:00:46,900 --> 00:00:49,380
value of NUM is less than zero.

13
00:00:49,720 --> 00:00:55,090
So let's try that out and open that up in our browser, go back out and refresh it.

14
00:00:55,270 --> 00:01:01,030
And when we hit start, we see that it runs that one item and then we can start building out our own

15
00:01:01,030 --> 00:01:01,720
sequence.

16
00:01:02,170 --> 00:01:05,930
Now, let's update this value to five and see what happens.

17
00:01:06,250 --> 00:01:07,780
So refresh hit start.

18
00:01:08,020 --> 00:01:11,140
So we've got one, two, three, four, five colors.

19
00:01:11,330 --> 00:01:18,730
We built out our array, the computer array, using the five colors, using the run sequence.

20
00:01:19,000 --> 00:01:25,570
So we're ready to move on to the next step where we can let the player match that sequence that was

21
00:01:25,570 --> 00:01:31,840
built out and check to see if the player actually matched the sequence and move them up a level and

22
00:01:31,840 --> 00:01:33,550
continue to play the gameplay.

23
00:01:33,880 --> 00:01:40,180
Letting a function run within itself is called recursion in JavaScript, and this is a great way to

24
00:01:40,180 --> 00:01:46,250
practice and get more comfortable with looping through functions and using recursion in JavaScript.

25
00:01:46,480 --> 00:01:47,830
So go ahead and try it out for yourself.
