Second "For" Loop


#1

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

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."


var text = "Generous George \ George is Generous";
var myName = "Mark";
var hits = [];

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


#2

I noticed that it should be b++, I fixed that already.


#3

and it is still not working? your name is not in text, so nothing will be found, so nothing will be pushed into the hits array


#4

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