Second loop not working


#1

I am not sure what is wrong with the below code.

var text = "Yo \ how's it going, my boy?";
var myName = "Jayram";
var hits = [];

for (var i = 0 ; i <= text.length ; i++)
{
if (text[i] === 'J')
{
for (var j = i; j < myName.length + i ; j++)
{
hits.push(text[j]);
}
}
}

Once I execute this code, I get this error message, "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. "

I'm sure I'm not supposed to be using semicolons until the end, but the code is not working. Please let me know what I am doing wrong. Thanks.


#2

I hope this will help

var text = "Yo hows it going, my boy \
Jayram?";
var myName = "Jayram";
var hits = [];

for (var i = 0 ; i <= text.length ; i++) {
    if (text[i] === 'J') {
        for (var j = i; j < myName.length + i ; j++) { 
            hits.push(text[j]); 
        } 
    }
};

You need to include your name in variable > text.
example:

var text = "Yo hows it going, my boy \
Jayram?";

Same name as the value of your > myName
example:

var myName = "Jayram";


#3

Yes it worked. Thanks,