I always get the error It looks like your second 'for' loop isn't pushing values to the hits array


#1

Hello everyone

When i try to run my code i always get the error:
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.

I'm pretts sure i missed something obvious, can you guys help me?

/*jshint multistr:true */

//insert a text
var text ="Hello, my name is Marco";
//Insert my name as a variable
var myName = "Marco";
var hits = [];
// make a for loop to check the text
for ( var 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

@capitain96,

You are using a semi-colon-; in your FOR-loop,
and as a semi-colon-; is an End-of-Statement indicator,
the so-called FOR-code-block { } will NOT be executed.

So change

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

into

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

#3

Thank you very much. It worked now.

Like I said, something obvoius (^.^)