Introduction to for loops


#1

https://www.codecademy.com/courses/javascript-beginner-en-NhsaT/2/4?curriculum_id=506324b3a7dffd00020bf661#


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]);
}


#2

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.


#3

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


#4

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