Doubt


#1

Hello,

I don't understand this part:

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

why +i ???

Thank you


#2

When you are writing code, it's best that you already have a plan for how everything should work out, and then you write the code. Code doesn't write itself, we need to know what we are doing.

What I mean is, that you're doing it the hard way of writing before you know what to write, the chance of doing the right thing is just.. a lot lower.

I suggest executing the code manually. The number of operations required is fairly low, so that is very doable. Then you can see what happens if you include or ignore the i there.

You can also just read the loop. Where does that loop start and where does it end?