Introduction to for loops


I cannot for the life of me figure out why I'm getting a SyntaxError: Unexpected string.

Thanks for your help.

var names = ["mom," "tifa," "oj," "sam," "robu"]; 
 for (var i = 0; i < names.length; i ++){
 console.log("I know someone called " + names[i]);


Your problem is that your commas are inside quotes. In other words, they are part of the string.
Change names to this:

var names = ["mom", "tifa", "oj", "sam", "robu"];

Do you see it? The commas between elements of an array can't be in the quotations.


Thank you. English teacher here. I've corrected too many student writing errors!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.