Before we start, did you try solving the workbook yourself?
If not, please click the link in the resources folder and follow the instructions for this workbook.
Workbook 6.6 is an extension of workbook 6.5.
We should only have one task that is to create a variable seat that starts at zero.
Simple enough.
And then it says using a for loop, find the number that matches the highest score and print it.
The index that corresponds to the highest score is the one where this condition evaluates to true.
So here we can say seat is equal to I.
And that's all here.
We can just say it's the gentleman in seat, the seat number that matches the highest score.
And that was really it.
Nothing to it.
And let's visualize the runtime.
You know what?
We need one breakpoint right beside the for loop.
And that's all.
Let me clean up over here.
Expand this.
So here we see our scores array has ten different random numbers.
We can see that the highest number is that index number one, actually.
So first I start at zero.
The score at index zero is 22,000.
22,000 is greater than our current high score of zero.
So this evaluates to true setting our high score equal to the highest score we've encountered so far.
And now the seat number equals the index that corresponds to this high score.
Now I equals one.
The score at index one 43,000 is greater than our current highest score.
So we update our high score again.
Now our high score is 43,000 and we set seat equal to the index that corresponds to this high score.
So now seat equals one.
And none of these scores are going to be greater than our current high score.
So this if statement is always going to evaluate the false.
Until the for loop eventually runs to completion.
All right.
So the highest score in the array ended up being 43,000.
And the seat number that corresponds to the score is C to one.
That was it.
I hope you enjoyed this breakpoint session.