Second for loop not pushing hits


#1


Hi everyone, I am stumped. I can't get the code to push the values to the hit array.
I have spent a few hours on these forums to see if I am missing something and my code looks like it should work.

It might be, that I have been looking at this for too long, but am I missing something really obvious here?

Thanks

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


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.


/*jshint multistr:true */
var text = "The first time Gareth went down the road. Next Gareth jumped in to a new car";
var myName = "Gareth";
var hits = [];
for (i=0; i < text.length; i++) {
    if (text[i] === myName[i]){
        for (var j = i;  j < (myName.length+i); j++){
            hits.push(text[j]);
        }
    }
}


#2

your if condition is wrong, you should check if text[i] equals the first letter of your name


#3

Hi stetim94, found the problem just as you replied. Thank you. The weird thing is that code was passed as ok from the previous lesson. Onward I go. Thanks again.


#4