Can anybody help me with this?


i tried to change something last day but now i am getting this error continuosly?whats wrong with it can anyone help?

Oops, try again. Make sure you're pushing letters to the hits array!

var text=" Rushabh Shah Rushabh Shah Rushabh Shah Rushabh Shah";
var myName="Rushabh Shah";
var hits=[];
for(var i=0;i<=text.length;i++){
     if(text[i] === myName[i]){
        for(var j=i;j<i+myName.length;j++){
// I dont know whatas wrong here?


Hi @rushabhj

In instruction/theory its written , Back in previous Chapater

"If we find the first letter of the name, start the second for loop!" This loop says: "I'm going to add characters to the array until I hit the length of the user's name."

It means that we have to compare first letter of myName with text's characters.

Check this line of code...

if(text[i] === myName[i])


In your if statement, you are checking if(text[i] === myName[i]).
Here is an example for the first run, when i = 0:
if(text[0] (a space) === myName[0] (a R). This is not true, so the if statement will not run.
This is the same until the last run, when i = 52.
if(text[52] (which is 'undefined') === myName[52] (which is again 'undefined'). Since they are both undefined, they are the same, and so the if statement runs. However, in your for loop within this if statement, you say hits.push(text[j]);. Since text[j] is 'undefined', your array of hits now contains no letters, just 'undefined'. Therefore,

You aren't.

Please tell me if this is unclear.


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