Totally Lost- Your Second For Loop


#1

I'm completely lost at this section. I keep going over the past several lessons, but I just don't understand what I'm being asked to do. I'm specifically having trouble with the terms "hits" "push" and "array," as used in this context. Can anyone explain this in a different way?
If it helps, this is the code I've come up with so far (it doesn't work):
/*jshint multistr:true */
var text = "There's an elephant fourteen sixty Meredith badges one two on the Lemons apples Meredith I'm voting for energy It takes a lot of work.";
var myName = "Meredith";
var hits = []
for (var i=0; i< text.length; i++) {
if (text[i] === "M") {
for(var j = text; j+myName.length; j++){
hits.push(text[j])
}
}

}
console.log(hits)


#2

should be,

j < i + myName.length;

#4

Still not working, unfortunately. I just tried:
/*jshint multistr:true */
var text = "There's a $25,000 bonus for select lesees. Meredith supplies more abundant energy meand more affordable Meredith I'm voting for energy. It takes a lot of work.";
var myName = "Meredith";
var hits = []
for (var i=0; i< text.length; i++) {
if (text[i] === "M") {
for(var j = text; j < i + myName.length; j++){
hits.push(text[j])
}
}

}
console.log(hits)


#5

We need to set j to the current value of i so the inner loop iteration begins with that index.

var j = i;

#6

So the second for loop should look like this?

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


#7

Yes, that looks better, now. Remember to end line statements with a ;

hits.push(text[j]);

#8

Still not working! I'm now using:
/*jshint multistr:true */
var text = "There's a $25,000 bonus for select lesees. Meredith supplies more abundant energy meand more affordable Meredith I'm voting for energy. It takes a lot of work.";
var myName = "Meredith";
var hits = []
for (var text=0; text < text.length; text++) {
if (text[i] === "M") {
for (var j = i; j < i + myName.length; j++){
hits.push(text[j]);
}
}

}


#9

By using the same variable in the loop, you wipe out the text. Try writing,

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

#10

That worked for me mtf, thanks

My code
/*jshint multistr:true */
var text = ("Hey, my name is Susan \
do you know my friend Loretta? If you \
see her could you ask Loretta to send \
me a text, thanks.");

var myName = ("Loretta");

var hits = []

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