j<(i+myName.length)


#1


https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/7?curriculum_id=506324b3a7dffd00020bf661


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.


#2

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


#3

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


#4

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


#5

i sort of get it, i guess.
thanks!


#6

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