Syntax error; help my grammar!


#1



I'm getting a SyntaxError: Unexpected identifier error when I run this code. My guess would be it's a typo somewhere and I just can't recognize it as such. Any help?

Thanks.

var names=["John", "Tim", "Andrew", "Grace", "Christie"]
var nameList = ""
for (var counter=0; counter<names.length; counter++) {
    if counter=names.length {
        nameList = nameList + " and " + names[counter] + "."
    };
    else {
        nameList = nameList + names[counter] + ", "
    };
};
console.log("The names of my siblings are " + nameList)

#2

The above contains two syntax errors:

if (counter === names.length) {

If I'm reading this correctly, the exercise probably wants one name, one line, not a sentence, so your code should just be logging out the names inside the loop.

Please post a link to the exercise so we can read the instructions. Thank you.


#3

Thanks, that solved it!

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

I was just trying to write a proper for loop that included an if/else statement.