Need help with second "for loop". Thank you


#1

/*jshint multistr:true */
var text = "Andy is listening to The Who right now and \
Andy is trying to decide if Andy likes this song.";
var myName = "Andy";
hits = [];
for (var i = 0; i < text.length; i++){
if (text[i] === 'A') {
for(var j = i; j < myName.length; j++){
hits.push(text[j]);
newArray = [];
newArray.push('Andy');
newArray[0];
}

}

}

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


#2

I think there may be a problem with your Second for. This was mine and it passed!
/*jshint multistr:true */

var text = "Hello, how are you \
doing? My name is Anna.";
var myName = "Anna";
var hits = [];

for (i=0; i<=text.length; i++){
if (text[i] === 'A'){
//Do something
for(var j = i; j < (myName.length + i); j++)
{
hits.push(text[j]);
}
}
}


#3

for(var j = i; j < myName.length +i ; j++) only that is ONE problem " +i "

:smile:


#4

this worked for me, thank you