Second loop is working but not letting me pass


#1


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


The error message is "Careful: your second 'for' loop should stop when it reaches its current point in the string
+ myName.length." When the console prints 'hits' hit comes up with the full name - nothing more, nothing less.
No idea what I'm missing in my loop.


var text = "Sometimes Alex wonders what Josh is currently doing"
var myName = "Josh"
var hits = []

for(i = 0; i< text.length; i++){
    if( text[i] === myName[0]){
        for( var j= i; j < (i + myname.length ); j++){
            hits.push(text[j]);
        }
    }
}
console.log(hits)


#2

I believe it has something to do with your second for loop.

for( var j= i; j < (i + myname.length ); j++){

myname should be myName.


#3

Thanks, that fixed the problem.


#4

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