5. Your second "for" loop help


#1



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


In this lesson, everything seems to be going well except I ran into a problem at the second for loop. This may sound stupid, but I'm sure how to stop my loop 'When it hits the value of the first iterator (say, i) plus the length of your myName variable.' if somebody could break it down so it's much easier to understand it'd be very appreciated. Thanks in advance!


var text = "Ibra Ibra Ibra";
var myName = "Ibra";
var hits = [];

for(var i = 0; i > text.length; i++) {
    if (text[i] === myName[0]) {
        for(var j = i; j > /*area where I don't know what to do */; j++) {
            hits.push('Ibra');
            hits[0];
            }
        }
    }


#2

Alright, I fixed the problem. Turns out I actually had the wrong operator for the second area of the for loop, which was why I was confused. When I flipped the > with < I got it correct.

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


#3

Nicely solved, i wrote a rather extensive answer yesterday on this question, you can find it here, maybe worth the read


#4

I probably should've looked there first!


#5

You can also search the forums for more reply's, there are many good answer which explain the second for loop, to improve your understanding


#6

Will do! What a great way to improve