Pls Help! - Random alphabets: Passed 5/7 but wrong output


Hey guys!

So I am new to the board and I usually never post but go through all the posts to solve my problems but this time I am frustrated enough to just post my problem. I simply do not understand what the problem with my code is: Why is my output displaying random alphabets instead of "uzair"? (See photo)

Two more question to anyone looking for extra karma points:

1) Why is "i = j" in the second loop?

2) Why do we write: "j < (myName.length + i)" and not "j < myName.length"?

Any help is appreciated


Greetings from Pakistan

Replace this line with your code. 
<img src="//" width="690" height="467">

indent preformatted text by 4 spaces


The output is correct given the inputs. How do you usually write your name? 'uzair' or 'Uzair'? That's part of the problem. You are searching for lowercase u and there are two other u's in the mix. up and much.

This program is not meant to find your name, as such, just the first letter. The letters that follow can be anything. The inner loop pushes five characters to the array, one at a time as it iterates the text string from text[i] on the left to text[i + myName.length - 1] on the right.

j = i sets the start of the inner loop to the current position in the string.
j < i + myName.length sets the endpoint.


Yo, what's up uzair? Not much uzair, you tell uzair
           i = 11

So j will be set to 11, and the upper bound will be j < 16. The hits array will look like this at completion of the inner loop:

['u', 'p', ' ', 'u'. 'z']

Yo, what's up uzair? Not much uzair, you tell uzair
              i = 14

So j will be set to 14, and the upper bound will be j < 19. Now the array will look like this:

['u', 'p', ' ', 'u'. 'z', 'u', 'z', 'a', 'i', 'r']

And so on. If you don't want any false u's, then use the proper name and search for U or myName[0].


You are an angel!. Timely reply and also extremely logically well explained! Thank you sir!