4/8 Contact List: "Unexpected Identifier"


#1

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
}
steve: {
firstName: "Steve",
lastName: "Smith",
number: "(345) 777-7777",
}
michael: {
firstName: "Michael",
lastName: "Paul",
number: "(815) 363-6789",
}
jake: {
firstName: "Jake",
lastName: "Letmanski",
number: "(847) 565-8976",
}
};
I was wondering why this code did not work when I hit save and submit. The error message that came up was "unexpected identifier."


#2

The unexpected identifier(s) are, steve, michael and jake. Can you reason what might be the cause of the error?


#3

Thank you for the feedback. I was able to figure out what was wrong.


#4

Can you please elaborate? Having the same problem.
Thanks.


#5

I am having the same problem. i think using the literal method is the most readable. I believe my curly braces are in the right place and that I have curly braces and proper syntax for all of my friends. I am getting the same unexpected identifier. You are saying that the issue is with the last 3 friends. I can't reason why. I would appreciate help understanding the error.
Thank you

var friends = { 
    jill: {
        firstName: "Jill",
        lastName: "Jones",
        number: "(301) 444-4444"
    }
    jack: {
        firstName: "Jack",
        lastName: "Black",
        number: "(410) 666-6666"
    }
    bill:{
        firstName:"Bill",
        lastName: "Gates",
        number: "(240) 555-5555"
    }
    steve: {
        firstName:"Steve",
        lastName: "Jobs",
        number: "(302) 888-8888"
    }
};

#6

Same error as mentioned above. each primary key is a new property of friends. Properties are comma separated.


#7

Sorry, this doesn't make sense to me.
In the examples, we learned previously when using object literal, we separated each property using the curly braces. Are you suggesting that I don't need the curly braces but rather replace them with commas?

To be clear "primary keys = names of friends (jill, jack, bill, steve)?


#8

Yes. Consider,

var friends = {
    bill: {},
    steve: {},
    jack: {},
    jill: {}
};

#9

I feel like hugging you right now! lol
GOT IT! My mind wouldn't allow me to consider using }, versus }; or just }
It was almost like I was creating a massive run-on sentence.

Thank you!


#10

Supplement:

When {} is preceded by = it gets a semi-colon after.

When preceded by : it gets a comma after.

When not preceded by either, it gets neither semi-colon nor comma.

When {} is followed by while () the statement ends with a semi-colon.

Eg.

function foo () {}
for () {}
if () {} else if () {} else () {}
while () {}
switch () {}

do {} while ();
var bar = function () {};
var obj = {};
var objobj = {
    prop1: {},
    prop2: {},
    prop3: {}
};

#11

THIS ^^ is extremely helpful. Thank you.