Your second "for" loop


#1


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


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 = "My name is Nish. Nish is learning to code.";
var myName = "Nish";
var hits = [];
for (var i = 0; i < myName.length; i++){
    if (text[i] === myName[0]){
        for (var j = i; j < (i + myName.length); j++){
            hits.push(text[j]);
            console.log(hits);
            }
        }
}


#2

corrected as suggested by @stetim94
for (var i = 0; i < myName.length; i++)

there you need to make change!

hint**
i < myName.length;


#3

i disagree with @greentreemee

you need to make a change to your first for loop

you only loop till end myName.length, you need to loop over text


#4

I don't understand. What am I missing?


#5

Thanks I changed the first loop so it loops over text and it works now.


#6

there is a problem with your first loop ^


#7

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