5/7 having trouble keeps saying "Oops, try again. Make sure you're pushing letters to the hits array!"


#1

/*jshint multistr:true */

var text = 'My name is Lock. Whats yours?';
var myName = 'Lock';
var hits = [i];
for(var i = 0; i < text.length; i++) {
};
if (text[i] === "L"[0]) {
for (j = i; j <= (i + myName.length - 1); j++) {
hits.push(text[j]);
}
};


#2
    var text = 'My name is Lock. Whats yours?';
var myName = 'Lock';
var hits = [];
for(var i = 0; i < text.length; i++) {
if (text[i] === "L") {
for (j = i; j < (i + myName.length); j++) {
hits.push(text[j]);
}
}
}

You're second loop should be inside the first loop. :wink: I've also done some other chages to the code. Ask if you are curious of some changes I made. :smile:


#3

In the second for loop try this:

for (j = i; j < (i + myName.length); j++) {
hits.push(myName);
}

It may not be exactly what they say they want, but it worked for me!


#4

That will add your name to the array once for every letter in your name, and it makes the second loop preatty usless. Try to use text[j] instead! It will add your name, letter by letter, to the array each time it finds your name in the text! :blush: