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


Here is my code. I'm pretty sure this should push to the hits array so I'm confused as to why it keeps giving me this error.

/*jshint multistr:true */
var text = 'My name is Dan and I am the greatest. Everyone loves Dan';
var myName = 'Dan';
var hits = [];

for(i=0; i<text.length; i++){
if(text[i] === myName[i]) {
for(j=i; j<(i+myName.length); j++){


A good start would be to add a print in the place where it's pushing letters to see if that's executed and if it's got the right letters.

Can also print out the final result.

Can also print before and after the pushing to see if it really was pushed

After doing some or all of that (perhaps there are other things that could be printed out as well) you should be able to say quite a lot about where the problem is and either solve it or ask something more specific.


your if condition:

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

you should check if text[i] equals the first letter of your name


That was exactly the problem... needed to compare to myName[0] instead of myName[i] thanks so much