What am I doing wrong here?


#1

/*jshint multistr:true */
var text = ("Peter, Peter, Peter,");
var myName = ("Peter");
var hits = []

for (var i = 0; i < text.length; i ++) {

if (text[i] === "P") {

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

hits.push(j);

}
}
}


#2

Your second for loop should stop at

myName.length + i

Also you are not wanting to push j which is simply a number. You are wanting to push characters from your text string.


#3

How exactly do you do that?


#4

I think thats it:
hits.push(text[j]);


#5

Is this what you want me to do because it is not working

/*jshint multistr:true */
var text = ("Peter, Peter, Peter,");
var myName = ("Peter");
var hits = []

for (var i = 0; i > text.length; i ++) {

if (text[i] === "P") {

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

hits.push(text[i]);

}
}
}


#6

In your second loop

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

 hits.push(text[i]); // text[j]  

}

#7

Its says there is a syntax error

/*jshint multistr:true */
var text = ("Peter, Peter, Peter,");
var myName = ("Peter");
var hits = []

for (var i = 0; i > text.length; i ++) {

if (text[i] === "P") {

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

hits.push(text[j]);

}

}
}
}


#8

Morning,

there is one closing curly bracket to much.

i will look closer later


#9

I too am facing the same problem. It continues showing the same error message,that

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="Blah Blah Blah Erica blah Erica";
var myName="Erica";
var hits=[];
for(var i=0;i<=text.length;i++)
{if(text[0]==='E'||text[0]==='e'){

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

  hits.push(text[j]);
hits[0];
}
}

}


#10

It keeps saying, Make sure you're pushing letters to the hits array!