5. Second "for" loop- Please Tell me what I did wrong


I'd appreciate any help. I've scoured the forum and can't figure out what I did wrong. Anyone?

 var text="I like chocolate josh he does josh"
var myName="josh"
var hits=[]
for (var i=0;i<=text.length;i ++);
if (text[i]==="j"){
   for (var j=i;j<i+myName.length;j++) 


Semicolon after for terminates the loop.

You should correct that line:

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

Instead of semicolon you should open a block with {.

Take a look at this condition:


We are indexing characters starting from 0. This means that text[text.lenght] does not exist :smile:


LOL Thanks man. spent hours on that.


You're very welcome :smile:


Hey @arcrunner89146,

Remember, it's a for loop. What does a loop have? Two corresponding brackets.

The semi colon that's after the for loop makes everything that's in the same line/part of the loop canceled, making the for loop useless. Take away the semi colon and add two corresponding brackets that start after the for loop and at the end. :smiley:



My computer didn't load, didn't see it. :sweat_smile:

Ignore this all. LOL


Well, I have to go, my classes start in 40 minutes.

You can answer next question without fearing that I will be faster :smile: Have a nice day!