5/7 Second "For" Loop Help!


#1

Checked other users who have the same issue and Im still not quite getting this. I understand what they're asking me to do but I can't get the coding together on how how the 2nd "For" loop is going to run after the 1st one....here's what I have so far....

var text = "My name is Niquelle and Niquelle likes Java Niquelle";/*jshint multistr:true */
var myName = "Niquelle";
var hits = [];
for(i = 0; i < text.length; i++);
if (text[i] === myName[0])
{
for(j = i; j < i + myName.length; j++);
hits.push(text[j]);
}
}
console.log(hits);

WHAT AM I DOING WRONG?


#2

/*jshint multistr:true */

var text = "My name is Niquelle and Niquelle likes Java Niquelle";

var myName = "Niquelle";

var hits = [];

for(i = 0; i < text.length; i++); {
if (text[i] === "N") {

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

  }

}
}


#3

So the first part for you was that you tried to use the variable name myName to start with, which is completely understandable, but it has to find it from text instead.

The next part was my problem as well.. I had to look around a lot to figure out the (myName.length + i) in the second for loop.


#4

@volcania ok so im assuming the order we place (myName.length + i) makes a difference....

Its still not running though, now it gives me an error message stating "Unexpected Identifier"


#5

j = i; j < ( myName.length + i ) j++);
                                ^

you forgot a thingy!


#6

Yeah I'm sorry I missed some other things in your code but I could only edit it once.. I ran this and it checked out on my browser:

var text = "My name is Niquelle and Niquelle likes Java Niquelle";

var myName = "Niquelle";

var hits = [];

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

    }

}

}


#7

haha yeah.. the one I just posted 5min ago I actually ran :smile: sorry everyone!


#8

i have to say this had to be my most difficult one yet....finally go it with both your help @volcania & @lolman , thank you so much!