Second for loop isnt pushing anything into an array


#1


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


My code keeps returning an error saying that my second for loop isnt pushing anything into the array


/*jshint multistr:true */
var text = "gevhgvszhfzshb hfhgavigsevfvks vfkghzcwfdg Max imoaksvefkhzh fkhgv Max gsvzhfgvish gvxihg Max"; 
var myName = 'Max';
var hits = [];
for(var i = 0 ; text < text.length; i++ )
{
    if(text[i] === "M")
    {
        for(var j = i ; i < (myName.length + i); j++)
        {
            hits.push(text[j]);   
        }
    }
    
}


#2

I think this discussion can help you out:


#3

your first for loop, in particular the condition of your first for loop:

text < text.length

you use i to loop over your text, shouldn't you then check if i is smaller then the text length?


#4

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