It says I did it, but I didn't


#1

It says I did everything correctly, but it just logs to the console every single letter, which must have been passed to hits. I don't understand how the system even works to debug it. Can someone help out and explain what I did wrong? Here's my code:

/*jshint multistr:true */

var text = "aldnav sakjnf Eric \
Ljfal gbjaj Eric afjsalfj \
Eric ahasthpoa";

var myName = "Eric";
var hits = [];

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

if (hits.length === 0) {
    console.log("Your name wasn't found!");
} else {
    console.log(hits);
}

#2

That's probably what it is supposed to do, isn't it?


#3

No. It's only supposed to log the letters to hits that are the letters of my name.


#4

in your for loop that is inside of your other for look and if statement you wrote
" for (var n = 1; ... "
and it needs to be " for (var n=i ... "


#5

thanks for providing the solution to this