Could not be able to run the code


#1


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

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.

var text = "dhadkd ksaoaj avinash kjwoei avinash cfewfosjdhsdoksdmd ldsoavinashewpfekwpe";
var myName = "avinash";
var hits = [];
for (var i=0;i<text.length;i++)
{
    if(text[0]==="a")
    {
        for(var j=i;j<=i+myName.length;j++)
        {
            hits.push(text[i]);
            hits[0];
        }
    }
}


#2

lets look at this condition:

if(text[0]==="a")

the first character of text is d, so this condition is always false, your second for loop never runs, nothing gets pushed


#3

thanks.........
:slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.