Now it's time to build our project with arrays and also for loops.
If you remember, the project was I will give my application three colors and will restore the three
colors and return the three colors as an alert.
You can return as a console as well, but I chose as an alert.
So the first part of my code I need to create an array, but I cannot give the items inside of the array.
I need to dynamically add the items inside of the array, but at least we need an array to start.
So my array is going to call list colors, something like that or color list.
Better color list.
And the color list is an empty array.
I'm going to leave.
Like this color list is an empty array so I can start adding items to my array later on.
And because the prompt must show, must pop up three times, I need a for loop, so the fourth loop
will start in zero and it goes to two or three in our case or equal to three, or start on one end equal
to three.
But it needs to loop three times and every time it loops, it needs to ask another question.
And every time it gets the answer, in our case, our color, it needs to get this information, this
data, and insert into the array.
So let's go for the for loop.
So the for loop is let I equals to zero.
Where I must be less or equal to two.
So he's going to spin for three times the zero, the one and the two.
So let me just make some spaces here.
And then I.
Has an increment of one.
So every time it loops, what should I do?
I'm going to create a new variable called color.
So this variable color is going to have a prompt.
And the prompt is the question to enter the color.
So prompt parentheses and please enter the plate into the color.
Please enter color.
Something like this.
Please enter the collar.
The result of this will be inserted to collar list.
You will be inserted to my array.
But how can I insert something into an array?
You may be thinking, okay, I can call the array Index starts on index zero, but then I have to keep
adding this number.
There is a function called push.
Let's go.
Sorry.
Functional method called push.
These methods will insert into the array wherever is typed to the.
Variable color.
So just recapping.
The prompt will show.
Please enter a color and I enter the color blue.
So blue.
Is.
The data inside of the variable color.
The next statement is.
Insert the information inside color to the array color list.
So it's going to insert right over here.
And then is going to run the loop again and ask the second question.
And then the third question.
Let's see if that works.
Oh, I have no alerts.
I have no alerts.
My last one is going to be alert to and these alert will be your list.
Of.
Callers ace, and then I will add the color list.
Simple like this.
So your list of color is plus the color list.
See if it works.
Save the config and go to the prompt.
Please enter a color.
I will enter blue.
If I can type blue the second color, it doesn't say the second.
And you fix that?
Yeah.
The second color green.
The third color will be red.
Your list of colors is blue, green, red.
It works, but I need to fix something else here.
As far as I remember, the the initial request was not request, but I remember seeing the.
Please enter your color.
One, color two and color three.
How can I solve this?
Please enter the color and let me just take these away.
I'm going to add the I as a number.
And then I'm going to add the.
Please enter the color space.
The number space.
Should I get a space here?
No, I think without a space.
This.
I think this.
This is going to work.
Please enter the color.
Zero.
And the color zero won't work.
Color zero won't work.
Color zero doesn't sound good.
Yeah.
So I'm going to start on one.
And one, two, three.
So please enter the caller.
One should be.
Please enter the caller.
One ock blue.
Please.
Type A wrong.
I mistype blue color to red color three yellow.
And I have blue, red and yellow.
But the numbers did work, so I'm happy with the result.
Can I improve this?
Yes.
Should we improve that?
Why not just go crazy?
Just add whatever you want.
Maybe you rephrase this and please enter the color number.
And then the number.
Color.
Number one.
Color number two.
Color number three or your list of colors is and color.
Number one.
Color number two.
Color number three.
I don't know.
You can you can do a lot of different inputs and outputs over here, but I kind of like the result.
Yeah, we did work with an array.
We learned how to push an information from user input into the array and as I said, I'm happy with
the result.