In this example we'reworking with arrays.
And there's a few thingsyou got to watch out for, especially whenyou're taking user input to create the arrays.
Your arrays can grow.
So you just need to declarea variable, var grades, with the brackets here.
This creates an empty array.
Then I have a var grade equals5, which I will change here.
But that's my whilegrade not equal equals zero, that's my triggerso we don't want it to start with zero becausethat will make it not run the way I want it to.
Then we've got total ofzero and a counter of zero.
So I've got analert for my users, "Enter 0 when you're doneentering the grades.
" And then while gradeis not equal to zero it's going to prompt for"Enter the test score.
" It's going toconvert it to an int, and then it's going to checkto make sure it's not zero because if it's zerowe don't want to add it to the end of the array becausethat would affect our results on how we average it.
So that's critically important.
So as long as it'snot zero we'll have grades counterequals grades.
So we're incrementing counterright here, counter plus plus.
That we'll keep adding the nextitem onto the end of the array.
And then we can gothrough the array.
And I'm doing this two times.
We could actuallydo this in one spot.
I'm just showing you that wecan do multiple things to it.
But it would totallywork the same way if I commented this out.
And this is a goodway to do testing.
We could totallyjust go through here and make sure we changeour increment variable and save that.
So now we can addthe total here.
And we can also have itwrite out the test score.
And I'm adding a breakin HTML so each one goes onto a new line.
I'm doing thatinstead of a paragraph because I don't wantblank lines between them.
And then we have our averagetest score let's go ahead and run this thing.
So I'm going to do70, 75, 80, 85, 90, 0.
And it gives us ourgrade for each test and our average score of 80.
So that's a simple wayfor working with arrays.
And you'll notice that arraysand for loops work perfectly together.
For loops one of the easiestways to step through an array.