5. Second "for" loop not pushing values to array


#1


5. Your second "for" loop


Every time I run my code I get this error message:

Oops, try again. It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable.

I can't figure out why it's not pushing to the hits array. Any suggestions?


/*jshint multistr:true */
var text = "text text text Randy text text Randy text text text text \
            Randy text text text text";
var myName = "Randy";
var hits = [];

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]);
		} 
    }    
}


#2

Should be less than.

Aside:

You can make it search for any name by changing "R" to myName[0].


#3

Thank you for the insight, its much appreciated.


#4

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