2nd For Loop trouble (yes, I check the archive)


#1

Okay maybe I'm just not seeing it. I get the classic "you're not pushing" error. What am I doing wrong?

/*jshint multistr:true */
var text = "Mitchell is the best, don't you love Mitchell";
var myName = "Mitchell";
var hits = [];

for( var text = 0; text < text.length; i++) {

 if (text[i] === myName[0]) {

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

}


#2

Just do:

hits.push(text[j]);

You were on the right track, just remember it's J instead of I because you're in the second loop.


#3

Thanks so much, after staring at it for a while I'm not sure how I missed that :smiley: :grin: