Plz help! <3


Would really appreciate if someone could tell me what's wrong with my code? Thank you so much :smile:

var text= "Hema did I mention that my name is Hema";
var myName="Hema";
var hits=[];
for (i = 0; i < text.length; i++){
if(text[i] === "myName"){
for(var j = i; j < myName.length+i; j++); {


There are two things wrong that I can spot.

The most immediate fix would be that you have surrounded myName (your variable) in quotes within your if statement. The statement will the not be pulling the value within the variable, but will literally be looking for "myName" as it is a string.

The second is that you're iterating through your text variable one character at a time, matching it with "myName' on each Iteration, you're comparing one character to a string.

What you are asking is

// text[4] will return 'a'
is text[4] === to the entire string 'myName' ?

// If you had used the original variable, it would've been still 'Herna'
is text[4] === the entire string 'Herna'

A link to the lesson would be helpful for providing any further advice.