Adding properties


#1

HI,

I am getting an unexpected identifier with the code below and I don't know why :

var friends = {};

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(987) 927-5642"
}
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(435) 675-8769"
}
};


#2

$ node abelbrown.js 
/tmp/js/abelbrown.js:9
steve: {
^^^^^
SyntaxError: Unexpected identifier

#3

I am sorry but I didn't understand your answer.


#4

Same error, more verbose, points at what it refers to.


#5

you have the same pb ?


#6

Nope. I ran your code and showed you the resulting error message.

Since you were saying that you didn't know why you were getting that error message, I added the information of what exactly the error message is referring to as the unexpected identifier. Further, it gives you the information that it's possible to run the code in other interpreters to get more information.

Making observations and comparing them to our expectations is how we figure out what we need to change.

So, something was unexpected, that means you'll have to ask yourself when it would be expected and what that looks like.


#7

found the solution. Needed the comma juste after the curly brace in the middle

var friends = {};

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(987) 927-5642"
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(435) 675-8769"
}
};


#8

Thank you. I will follow this procedure next time.

The weird thing though is by adding the comma, the code worked. How can the error was an unexpected identifier then ?


#9

When you write code you are following patterns that the interpreter/other software knows how to read (parse)

If you write something that doesn't match any pattern, then what you wrote was not among expected options.


#10

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