Why missing after for-loop intializer error?


#1


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.


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


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++){
    nameLetters.push(myName[i]);
};
var showName = 1
while(showName){
    console.log("My name is spelled " + nameLetters);
    var showName = 0;
};


#2

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?


#3

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