5/7: It's right, but could someone help me find out why?


#1

Hi everyone,

I'm having trouble understanding why we need to add i to the length of myName.

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

Thanks to anyone who can help me understand this!


#2

The loop starts at i and should then continue for a number of steps equal to the length of the name


#3

Thanks! But why doesn't that make it go one step past the length (aka too many) ?

In other words, why doesn't the j count to the length of myName without the +i ?


#4

bumping. have the same exact question as you efhjones!


#5

Execute it manually and see for yourself. Pick a short name to save yourself some trouble.

Be careful to not do what you expect to happen, make sure you're executing the code as it says, not what you think it does - perhaps you expect it do to something differently from what it says and then you risk doing the same thing when executing the code manually.


#7

I've execute it manually, but I still don't understand what it's doing. I don't know why I have to add the count i to .length, shouldn't .length be long enough already...?


#8

If i is 454353 and the length of the name is 3, then you should loop through:
454353
454354
454355


#9

I'm sorry, thanks for your patience, I don't understand what you mean by this at all :confounded:


#10

What does i represent in your code?

What should your code be doing at each value of i?