1 00:00:00,180 --> 00:00:03,870 Before we start, did you try solving the workbook yourself? 2 00:00:03,900 --> 00:00:09,660 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,440 --> 00:00:12,110 Welcome to Workbook 6.3. 4 00:00:12,120 --> 00:00:17,250 Make sure that you launch the correct folder and task one is to create an array that stores files, 5 00:00:17,250 --> 00:00:19,110 in other words, string values. 6 00:00:19,110 --> 00:00:24,750 So here I will create an array that stores elements of type strings. 7 00:00:24,750 --> 00:00:26,280 What should I call the array? 8 00:00:26,350 --> 00:00:32,940 Let's say aisles is equal to an array of string values that we got from learn the part. 9 00:00:32,940 --> 00:00:34,500 Let me minimize this pain. 10 00:00:35,130 --> 00:00:38,640 And all right, what is task number two? 11 00:00:39,090 --> 00:00:42,270 So a customer apparently is looking for coffee. 12 00:00:42,270 --> 00:00:47,190 I can confirm that create a for loop to a search is the array for the coffee aisle. 13 00:00:47,190 --> 00:00:51,630 So essentially, we need to search through every single element in the array. 14 00:00:51,630 --> 00:00:58,680 And when we find an element that matches coffee, we need to return the quote unquote aisle, the index 15 00:00:58,680 --> 00:00:59,580 of the array. 16 00:00:59,580 --> 00:01:01,260 So let's do just that. 17 00:01:01,890 --> 00:01:06,180 We will create a for loop that runs through the length of the aisles array. 18 00:01:06,180 --> 00:01:12,630 So I is going to start at zero and the loop is going to keep running so long as I is smaller than the 19 00:01:12,630 --> 00:01:13,770 arrays length. 20 00:01:15,840 --> 00:01:17,950 And every time the loop runs, we increase. 21 00:01:17,970 --> 00:01:18,990 I buy one. 22 00:01:19,870 --> 00:01:26,050 The length of the array is six, which means the counter I is going to start at zero until it eventually 23 00:01:26,050 --> 00:01:27,190 reaches five. 24 00:01:27,490 --> 00:01:32,770 So when the loop is running, we can use AI to index every single element in the array. 25 00:01:34,470 --> 00:01:41,280 And if we end up indexing an element that equals the value coffee. 26 00:01:45,300 --> 00:01:47,910 Then we're going to print the following message. 27 00:01:48,620 --> 00:01:54,350 We have that in I'll whatever I equals when this condition ends up being true. 28 00:01:56,200 --> 00:01:58,060 And then we can break the loop. 29 00:01:59,300 --> 00:02:00,140 All right. 30 00:02:02,150 --> 00:02:04,390 So that was task number two. 31 00:02:04,400 --> 00:02:07,580 Let us compare what we get against the final result. 32 00:02:07,580 --> 00:02:11,870 So this loop should break when I reaches an index of four. 33 00:02:11,900 --> 00:02:13,040 Let's try it out. 34 00:02:17,730 --> 00:02:19,360 Forgot to add breakpoints. 35 00:02:19,380 --> 00:02:21,180 Put one breakpoint over here. 36 00:02:26,040 --> 00:02:28,040 Our customer is asking for coffee. 37 00:02:28,050 --> 00:02:31,560 We see that coffee matches an index of four. 38 00:02:32,400 --> 00:02:35,610 So stepping inside the loop, I start at zero. 39 00:02:35,640 --> 00:02:38,430 The element of index is zero is apples. 40 00:02:38,430 --> 00:02:44,880 The string apples does not equal the string coffee, so the if statement gets skipped. 41 00:02:46,150 --> 00:02:47,590 Now I equals one. 42 00:02:47,620 --> 00:02:49,860 The element that index one is bananas. 43 00:02:49,870 --> 00:02:54,850 The string bananas does not equal the string coffee, so that gets skipped as well. 44 00:02:57,300 --> 00:02:59,190 Now I equals to the element. 45 00:02:59,190 --> 00:03:01,860 That index to candy does not equal coffee. 46 00:03:02,940 --> 00:03:07,710 I equals three the element that index three chocolate does not equal coffee. 47 00:03:09,170 --> 00:03:14,270 Now I equals for the string coffee does equal the string coffee. 48 00:03:14,270 --> 00:03:16,670 This evaluates to true printing. 49 00:03:16,670 --> 00:03:22,430 We have that in I'll whatever I equals when this condition evaluates to true. 50 00:03:23,540 --> 00:03:24,950 Printing our message. 51 00:03:24,950 --> 00:03:27,050 That's what we have learned the part. 52 00:03:27,050 --> 00:03:30,740 And because we found our item, we're done searching for it. 53 00:03:30,740 --> 00:03:32,300 So we break the loop. 54 00:03:33,530 --> 00:03:35,360 Upon breaking the loop were all done. 55 00:03:35,360 --> 00:03:38,630 So let's just continue with the runtime and it just ends. 56 00:03:38,810 --> 00:03:41,670 That was the solution for workbook 6.3. 57 00:03:41,690 --> 00:03:47,710 Now, I really want to emphasize when you're comparing two strings, always use the equals method. 58 00:03:47,720 --> 00:03:51,410 Do not ever use the double equal sine to compare strings.