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.
Welcome to Workbook 6.3.
Make sure that you launch the correct folder and task one is to create an array that stores files,
in other words, string values.
So here I will create an array that stores elements of type strings.
What should I call the array?
Let's say aisles is equal to an array of string values that we got from learn the part.
Let me minimize this pain.
And all right, what is task number two?
So a customer apparently is looking for coffee.
I can confirm that create a for loop to a search is the array for the coffee aisle.
So essentially, we need to search through every single element in the array.
And when we find an element that matches coffee, we need to return the quote unquote aisle, the index
of the array.
So let's do just that.
We will create a for loop that runs through the length of the aisles array.
So I is going to start at zero and the loop is going to keep running so long as I is smaller than the
arrays length.
And every time the loop runs, we increase.
I buy one.
The length of the array is six, which means the counter I is going to start at zero until it eventually
reaches five.
So when the loop is running, we can use AI to index every single element in the array.
And if we end up indexing an element that equals the value coffee.
Then we're going to print the following message.
We have that in I'll whatever I equals when this condition ends up being true.
And then we can break the loop.
All right.
So that was task number two.
Let us compare what we get against the final result.
So this loop should break when I reaches an index of four.
Let's try it out.
Forgot to add breakpoints.
Put one breakpoint over here.
Our customer is asking for coffee.
We see that coffee matches an index of four.
So stepping inside the loop, I start at zero.
The element of index is zero is apples.
The string apples does not equal the string coffee, so the if statement gets skipped.
Now I equals one.
The element that index one is bananas.
The string bananas does not equal the string coffee, so that gets skipped as well.
Now I equals to the element.
That index to candy does not equal coffee.
I equals three the element that index three chocolate does not equal coffee.
Now I equals for the string coffee does equal the string coffee.
This evaluates to true printing.
We have that in I'll whatever I equals when this condition evaluates to true.
Printing our message.
That's what we have learned the part.
And because we found our item, we're done searching for it.
So we break the loop.
Upon breaking the loop were all done.
So let's just continue with the runtime and it just ends.
That was the solution for workbook 6.3.
Now, I really want to emphasize when you're comparing two strings, always use the equals method.
Do not ever use the double equal sine to compare strings.