Why missing after for-loop intializer error?


UPDATE: seconds after posting (of course) I noticed I was using commas (which I thought was correct) instead of semi-colons in the for conditions.

I would like to have this code essentially run a for loop to gather each letter of my name, Andrew. Then in the while loop, without trying anything fancy, simply while the variable showName is true to print "My name is spelled " and the array of the nameLetters variable. I've stared at this and gone step by step through the code and cannot figure out where I have a syntax error. Any help would be appreciated.


For some reason I am getting "SyntaxError: missing after for-loop initializer" when I try to run this code

var myName = "Andrew";
var nameLetters = [];
for (var i = 0, i < myName.length, i++){
var showName = 1
    console.log("My name is spelled " + nameLetters);
    var showName = 0;


I ran your code (with semicolons in the for loop) through http://repl.it and it works. Maybe you just need to refresh the browser?


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