5. Second "for" loop which problem in the code?


#1

https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661

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.


/*jshint multistr:true */

var text = "some text here for make a test";
var myName = "Eric";
var hits = [];

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


#2

you don't need the parenthesis around the i + myName.length, and you don't have your name in any of your text


#3

and i don't really know if it changes anything but i don't have either of the console.logs that you have and mine is working. I'm pretty sure it doesn't matter but i figured i would point it out in case


#4

var text = "blah blah blah blah Eric blah blah blah \
blah blah blah blah blah blah blah blah blah blah blah\
blah blah Eric blah blah blah blah blah Eric blah blah";

you can use this and it should work


#5

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