Search text for your name


#1

Hey guys! Can you plz figure out the problem with my code..Its as follows:
/*jshint multistr:true*/
var text,myName,hits;
text="This is Aman. I love coding. Aman loves to code.";
myName="Aman";
hits = [];
for(var i=0;i< text.length ;i++)
{
if(text[i]===name[0])
{
for (var j = i; j < i + myName.length; j++)
{
hits.push(text[j]);
}
}
}

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.


#2

Hi this line

if(text[i]===name[0])

you save your name in a variable myName and not name


#3

Got it! Thanks for help.