Your second for loop is missing some fundamental logic in this scenario.
The second for loop should push out the name
hits when the if statement before it is equal to true. And for that to happen you need to first come up with a variable (
j in this case) and store the index that
i is on.
i serves as the anchor or location that we entered the second loop from.
j on the first iteration will be equal to
i. The second for loop will fire as long as
j is not longer than
i + myName.length. Remember
i is our anchor, so it shouldn't change. It serves as a good way for us to test whether
j is longer than the index we found 'G' + the length of the name we're trying to find. If it is longer then we should have extracted the name and there is no need to continue iterating.
Hope that helps. But if not feel free to visit this link where I went over this example in some detail.