Syntax error; help my grammar!


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?


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)


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.


Thanks, that solved it!

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