Your second 'for' loop


#1

https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661
I need a help for this exercise. The error says "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." even I wrote the code to push values into the array.

/*jshint multistr:true */
var text = "jsdivsdjhpeageahdeicbsjubcrwoahdb";
var myName = "peagea";
var hits = [];
for (var i = 0; i < myName.length + 1; i++) {
    if (text[i] === "p") {
        for (var j = i; j < i + myName.length; j++); {
            hits.push(text[j]);
        };
    };
};

What should I do?


#2
  1. i < myName.length + 1; out of range of myName variable. should be i < myName.length;
  2. You don't need semi-colon after if statement and for loops.
  3. You forgot to log results:

console.log(hits);

Updated 1.
And here should be:

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

Updated 2.
Your first for loop is wrong because it should compare every element from var text. So instead of:

for (var i = 0; i < myName.length + 1; i++) {
...
}

should be:

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

#3

Thank you, it worked, and for your clear explanation!


#4