Where's the error? "Your second for loop"


I don't know what I'm doing wrong. It's been hours and now I think this could turn into days. I've tried many different things. If it's something logical, it's certainly being overlooked.


/*jshint multistr:true */
var text= "anbioaijajiErinaheiaowejvijaErinealnvja;jvajiejfiejErinkaefjiwjivja;je;jaljiefjErin";
var myName="Erin";
var hits=[];
for(var i=0; i<text.length; i++){
    if (text[i] === "E"){
        for(var j=i; j < myName.length; j++)
        console.log (hits.push(j));}}

/*Oops, try again. Careful: your second 'for' loop should stop when it reaches its current point in the string + myName.length. */


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

there is problem with second part of your loop..
j < myName.length

when j starts at i It has to go over length of name.

Like if name is
myName = "Ryan"

and if loop starts at 4.. then you don't write this,,
for( j = 4; j < myName.length;j++)
but you write this..

for( j = 4; j < 4 + myName.length;j++)


You have to push letters/characters.


Thanks you!

Unfortunately, I'm still stuck...


Like @greentreemee said, you need to write something like this for your second for.

for(var j = i; j < (myName.length + i); j++) {

Then you pushthe character/ letters by writing this.


Let me know if that helped.


Yes it did!
I'm keeping this in my notes.


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