What could be the problem?


#1

the console says: ReferenceError: Invalid left-hand side expression in postfix operation

and thats the error message: Oops, try again. Did you remember to log the result of your search to the console?

what could be the problem? thanks in advance!

here is my code:

/*jshint multistr:true*/

var text = "blah blah blah blah Lawrence blah blah bah \
blah bah lbah blah blah blah blah blah blah Lawrence \
blah bah blah blah blaha blah";

var myName = "Lawrence";

var hits = [];

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

         hits.push(text[j]);
    }

}

}
console.log(hits);
if (hits.length === 0) {
console.log ("Your name wasn't found!");
}
else {
console.log (hits);
}


#2

Hi try to close your for loop its missing a )

for (var j = i; j < (myName.length + i) ++j;  <==

#3

Thank you for your reply, but unfortunately its the same two errror message as above :confused:


#4

After put the closing ) change also that

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

To

if (text[i] === "L")

#5

Thanks for the help, I made it with and without the [] brackets but its still the same


#6

for (var j = i; j < (myName.length + i) ++j; {

         hits.push(text[j]);
}

This looks like it could be your problem. for loops need to have this kind of syntax:

for(starting value; ending value; change) {

}

Right now you don't have the change separated from the ending value, also the right parenthesis needs to close the for statement