Log it! issuesd


#1



My code seems to be as directed, however I can't seem to get it to do as the instructions asked.

https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/6?curriculum_id=506324b3a7dffd00020bf661#


My code prints out [ 'e', ' ', 'a', 'l' ] and I have no idea why.


/*jshint multistr:true */
var text = "My name is Ande, I like alicia. \
alicia likes Ande. Ande is a strange name.\
Why was I named Ande?";

var myName = "Ande";

var hits = []

for(var i = 0; i < text.length; i ++)
{ 
    if (text[i] === 'A')
    {
        for (var j = i; j < i + myName.length; j ++)
        {
            hits.push(text[i + j]);
        } 
        break;
        console.log(hits)
    }
}
if (hits.length == 0) 
            {
            console.log("Your name wasn't found!");
            }
         else 
         {
        console.log(hits);
         }

Replace this line with your code.


#2

Hi this line

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

remove the i +


#3

Wow! that was the problem exactly. Why did that cause an issue?


#4

@wizmarco Wow! that was the problem exactly. Why did that cause an issue?


#5

I think it's because the i has been use in the first for loop and then on this line

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

you shoudl only .push() the letter the j from the second for loop so when you do that text[i + j] it give you another results.