Need a more basic understanding


I understand that this code outputs my name letter by letter into the array from the text. I can type it and retype it. I get it. I just don't understand why. I was hoping someone could break down the code with a little more depth.

especially at "for(var j = i; j <myName.length + i; j++)"

how does the length of the name + i incremented by 1 actually capture the name from text

for(var i = 0; i < text.length; i++) {
    if(text[i] === myName[0]) {
        for(var j = i; j < myName.length + i; j++) {


Read this to get an idear....


thank you that's perfect. but i'm still confused on this part

rightIndexFingerPos < (leftIndexFingerPos + myName.length);

that means the END of the loop is rightIndexFingerPos IS LESS THAN leftIndexFingerPos + however many characters your name is. right?

so confusing
why does that get the name exactly? is it possible to break that down further?


why is it LESS THAN leftIndex plus yourname? shouldn't it be EQUAL TO??


Maybe doing some reading in the Book


i appreciate it. i pretty much get it. just can't quite picture the whole process


The exercise is a un-exact =search your name= code construct......

What they try to achieve
is that you learn to to use =nested= IF and FOR-loop statements......

Within the exercise you are browsing through a given text,
and as soon as you find a letter
which matches the first-letter-of-the-associated-Value-of the-myName-VARIABLE
you will collect characters from the given text

  • starting from the position of the left-finger.... but you have put your right-finger on top of your left-finger, and
    • you keep your left-finger in place
    • you start collecting characters with your right-finger (the amount being myName.length -1 as you will start counting from virtual-zero, therefor you use the less-than < operator )

The down-side of the code
For instance
text="J.J.Cale was an old man he was J.J.Cale"
As the first-character of myName is a capital J
you would get the collection


so you have NO check if the collected characters are actually your name


Thank you bro that really helped. Less than cause of absolute zero. Itd probably be alot easy to understand if it was an exact search your name construct. Right. Thanks again.

But one more thing. Its j = less than name.length + i. The plus i is the actual search through text itself or the first letter in myName?



The i

  • is the position at which your left-finger is (and is preserved/saved as you work with j )
  • is the position at which you found the character matching the 1st character of myName
  • is the starting-point of you right-finger


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.