There is an unexpected token


#1

Hey,
So this thing is still kicking my butt. I did what you said. Any thoughts? Here's my code. I'm being told that there is an unexpected token.

var text = ("Sing, O goddess, the anger [mênis] of Alex son of Lord Shawn, that brought countless ills upon the Halawa Cell block B. Many a brave soul [psukhê] did it send hurrying down to the SBPD, and many a hero did it yield a prey to dogs")
var myName = 'Alex'
var hits = []
for (i = 0; i < text.length; i++) {
if (text[i] === 'A') {
for (var j = i; j < i; j++) { hits.push(text[j]); }
}


Help with Your second "for" loop!
#2
j < i + myName.length

It is not necessary to encapsulate a string in parentheses. It already has quote delimiters. This exercise is outfitted with a jshint multiline comment, meaning escapements are recognized:

text = "Sing, O goddess, the anger [mênis] of Alex son of Lord \
 Shawn, that brought countless ills upon the Halawa Cell block B. \
Many a brave soul [psukhê] did it send hurrying down to the SBPD, \
and many a hero did it yield a prey to dogs";

If your text has any line breaks (which I suspect it does) the interpreter will throw an exception. By escaping, we are permitted line breaks. Be sure that the jshint line is in your code at the very top. See lesson one if it isn't. You can copy it from there.

Be sure to respect JavaScript syntax for end-of-statement. We generally always write a semi-colon at the end of any line statement.

var myName = 'Alex';
var hits = [];

Space is free, so don't be afraid to open your code up so it can be more easily read.

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

may be written,

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

#3

HI,
What is the deal? I've tried this multiple times and looked through every single Q&A and nothing is working. I keep getting 'Unexpected Identifier.' Here's my code!

jshint multistr:true

var text = "Sing, O goddess, the anger [mênis] of Alex son of Lord \ Shawn, that brought countless ills upon the Halawa Cell block B. \ Many a brave soul [psukhê] did it send hurrying down to the SBPD, \ and many a hero did it yield a prey to dogs";
var myName = 'Alex';
var hits = [];
for (i = 0; i < text.length; i++) {
if (text[i] === 'A') {
for (var j = i; j < i + myName.length; j++; )
{ hits.push(text[j]);
}
}
if (hits.length === 0) {
console.log("Your name wasn't found!")
} else {
console.log(hits);
}


#4

Add an additional } after { hits.push(text[j]);


#5

No dice. Anything else?


#6

Do you have the jshint multistr:true commented out? That might cause the 'Unexpected Identifier'