Your second "for" loop


#1


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

var text = "Searching this code until it comes across Rebecca as a word, / have to put it in twice so Rebecca";

var myName = "Rebecca";
var hits = [];
for (var i = 0; i < text.length; i++)
    {  
        if(text[i] === 'R')
        {
           for (var j = i; j < (i + myName.lenth); j++)
           {
            hits.push(text[j]);
           }
        };
    };
console.log(hits);

#2

Your second for loop should stand on it's own and not nested in the other. It should be in the body of the if as said in the instruction. I believe that's why the interpreter says the second for loop should stop at that point.

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

};

Hope I helped! :slight_smile:


#3

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