Help with second for loop


#1

I cant figure out what is wrong with the second for loop. Keep getting this 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 = "My name is Mckinley. asdfa adfasdf adsfasdf"

var myName = "Mckinley"

var hits = []

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


#2

Take a careful look at your syntax. Your "For" loops have semicolons placed next to them when it should instead be two curly braces "{ }" to surround your code.

Remember a For loop should look like:

for(statements){
   code;
}

While you have put:

for(statements);
code;

I don't know if in your code you've used indentation, but if you haven't I'd recommend doing so. Reply if you still don't understand!


#3

@terasolver95195,


#4

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