Second for loop syntax error


#1

this is my code here:

var text=("hello, i'ts nice to meet you my name is, Jason.");
var myName=("Jason");
var hits=[];

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

        }
    }
};

it is saying that i have a SyntaxError: Unexpected token } but i cant seem to find it.


#2

@jason2921

It shouldn't be indexed as 0. It should be indexed as variable i otherwise will only test what is in the first letter of the string of variable text.


#3

okay that part makes sense but its saying Oops, try again. There was a problem with your syntax. and still is reading SyntaxError: Unexpected token }

This is the new code:

var text=("hello, i'ts nice to meet you my name is, Jason.");
var myName=("Jason");
var hits=[];

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

        }
    }
};

i did change the 0 to and i in the if statement is there any other reason it will not work?


#4

Thanks!! i got it i had an extra } all the way at the bottom of the screen too that was the syntax error.