Don't understand this for loop?


#1


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


Oops, try again. Careful: your second 'for' loop should stop when it reaches its current point in the string + myName.length.


/*jshint multistr:true */

var text = "I am from Australia but I live in England. \
I'm 17 years old and my name is Jennifer.";
var myName = "Jennifer";
var hits = [];

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


#2

i will contain the index of the first letter of your name, so then you want to use j to loop from the start till the end of your name (i + myName.length), so you need a condition which involves j and i + myName.length

and then you should increase j, so it can reach the end of your name


#3

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