I don't understand the logic behind this: j<(i+myName.length) in the second for loop : for (var j=i; j<(i+myName.length); j++)
what does it mean for j to stop at (i+myName)?

Replace this line with your code.


your name might occur multiply times in string stored in text

so our first loop loops over text, then we have an if condition to check for the first letter of our name.

so i will contain the first letter of your name (thanks to if condition)

then we make second for loop, to loop over our name and push the hits into an array

but we need a condition for our second for loop. given i contains the index of the first letter of your name, and since we are looking for your name, the length of your name + begin index is a good stopping point


i sort of get it.
but doesn't myName.length equal a number?


it does? but j and i are also numbers?

we use i as index to get values/letters from text variable (which contains strings)

we use j as index to extract your name from text variable


i sort of get it, i guess.


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