'Search Text for Your Name' (5. Your second "for" loop)


Hi I am stuck on this part of the lesson and have no idea how to proceed, if someone could help me it would be much appreciated.

ERROR: 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.

Here is my code...

/*jshint multistr:true */
var text = "My cousin just got engaged.";
var myName = "Anastasia";
var hits = [];

for (var i = 0; i < text.length; i++){
    if (text[i] === 'A') {
        for (var j = ; j < (myName.length + i); j++) {


in your second for loop, j contains the index of the letters you want to push in your hits array, so text[j] contains the letter you want to push into the hits array. So that is what i would do here:


the j is missing in your case. Your name should also be in your text variable, otherwise there is no match


I have changed the "hits.push(text[])" to what you told me to. I'm still really new to this code stuff and don't understand what you mean when you say my name should also be in my text variable. Could you please elaborate. Sorry for causing you trouble.


hits.push(text[j]) you have now?

well, the first for loop is looping over the string stored in your text variable, some code to prove my point:

var text = "My cousin just got engaged.";
for (var i = 0; i < text.length; i++){

anyway, then you have to the second for loop to look for your name (Anastasia) in your string (My cousin just got engaged.) stored in the text variable, but your name is not in there? Why do you think the track is called search text for your name? But then your name must be in the text (string stored in text variable)