6. Log It! SyntaxError: Unexpected token ILLEGAL


#1

Hiya,

In the previous exercise i kept getting "e", and i did think something was wrong. But now i'm getting this error "Unexpected token ILLEGAL"
Please do help, thank you :slightly_smiling:

this is my code
/*jshint multistr:true */

var text = "Hey, how are you \ doing? My name is Sneha.";
var myName = "Sneha";
var hits = [];

for (i= 0; i < text.length; i++);
if (text[i] === 'S');
// DO SOMETHING? - ADD TO ARRAY I'D IMAGINE?
for (var j =1; j < myName.length+i; j++){
hits.push(text[j]);
}
if(hits.length === 0) {
console.log("Your name wasn't found);
} else {
console.log(hits);
}


#2

You can only open if/else blocks with { but not ;
This applies to every if block in your code

NB: for every opening brace there must be closing brace


#3

You might wanna correct that statement there


#4

@rydan
Is it suppose to be j =0?

Also, i have added a { for all if and else statement as you suggested.

I've made these changes, but it still says it's illegal. Could you explain to me, what it means when it says Unexpected token ILLEGAL?

thank you :slightly_smiling:


#5

/*      the second for loop begins when the current character
        matches the first letter in myName. the loop will
        start at the index where you got the match(i.e.i) and will
        only run for the length of myName.
        
        Now we write this statement j<myName.length+i adding the value of 
        'i' to ensure that we always begin the second for loop at the 
        index where we found the match
        
        */

that error mean you are using something where you are not supposed to be using it. Usually related to syntax
Eg

A for loop is supposed to be written like this

while(some_condition){
       //statements
}

//writing anything other than the accepted format will give that error

#6

Take careful Note

for every opening brace { you must have a matching closing brace }


#7

@rydan

So, I have read through that and i THINK i have understood some of your pointers.

1) I have checked my for loops to see if it is following the format - which i believe it is.

2) i have changed j = i, because the loop has to be connected to i in order for it to work? Yes, no, maybe?
3) I have checked my opening brace has a partner :smile:

This is the latest code, it still says it has the same issue. I feel i might have overlooked something really small or have the wrong idea of the for loop format.

var text = "Hey, how are you \ doing? My name is Sneha. \ Sneha is very happy to see you and \ hopes you have a wonderful weekend! \ Sneha shall see into any problems that\ you may have in the next few days.\ Best Regards Sneha";
var myName = "Sneha";
var hits = [];

for (i= 0; i < text.length; i++);
if (text[i] === 'S') {

}   for (j =i; j < myName.length+i; j++){
hits.push(text[j]);
    }

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

Thank you again, you have been a great help :slightly_smiling: