5/7 Your second "for" loop


This is my Code

Can you tell me whats wrong?
errormessage = "Oops, try again. Make sure you're pushing letters to the hits array!"

it`s not working even if i write hits.push(myName[j]);


No semicolons after condition (or for loops).

This is written for conditions but it's the same for the semicolons here:

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



please take look at your for statement.

var text = "blah Julian blah blah blah \
blahblahblah Julian Julian";
var myName = "Julian";
var hits = [];

for (var i = 0; i < text.length; i++); // semicolon is wrong make a {
               if ( text[i] === "J") {
                         for (var j = i; j <= i + myName.length; j++); // same here replace ; with {
                         } // closing } is missing
} // closing } is missing

Need more Help?
Read this about for loops on MDN


The same way you've opened and closed the body of the if statement, you have to make a body for each for loop. Like that:

for (var i = 0; i < text.length; i++) {
  #this is the body of the for loop
  if (text[i] === "J") {
    #this is the body of the if statement

With that in mind, try and rewrite your own code. (You're really close) Also don't hesitate to ask more questions.


Hey guys, thank you very much for your help. Dont know why i didnt see that :smiley:

Now i can go on with the next lesson but the "push" throws out a "21" ? is that correct? I thought it should push a "6" because of "Julian" ?!

Or did i not understood the task ?


I'd have expected a 18 for 3 times "Julian". Could you show the updated code?


Here is the "final" code i saved:


Ok the problem is that you use <= meaning that you include the space after your name as well (you start counting at 0 so myName.length letters means < myName.length). You can console.log(hits) to see this as well.