Your second for loop


#1

don't quite know what is wrong here its telling me to make sure its pushing letters to the hits arrays

ar text = "hello, my name is Grantham ";

var myName = "Grantham";

var hits = [];

if (text[i]==="G");
{
for(var i =0; i < text.length; i++);{

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

 hits.push(text[j]);


 console.log(hits);

}
}
}

`


#2

Firstly the structure of your code is a bit off. you need to start it with your for.
There is also a few unnecessary semi colons.
Also this ++j should be this j++.

Study my code and figure out the differences.

for (var i = 0; i < text.length; i++) {

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

However everything above this is fine.

Let me know if you need further explanation.
If this helped you please mark my reply as the solution :slight_smile:


#3

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