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


#1


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. */


#2

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

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

hint**
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++)

Problem2.
hits.push(j)

You have to push letters/characters.


#3

Thanks you!

Unfortunately, I'm still stuck...


#4

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.

hits.push(text[j]);

Let me know if that helped.


#5

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


#6

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