0

I am learning Javascript on Codecademy, and after entering in my code to make a short contact list, it returns an error message of:

SyntaxError: Unexpected identifier

Here is my code:

var friends = {
    var bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "1800 4 charity",
    };
    var steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "1800 I have lots of jobs",
    };
};

Any help is greatly appreciated thanks :)

2
  • remove var and replace ; with , inside friends Commented Jul 1, 2014 at 6:41
  • The friends object needs to look more like the inner objects: no var or semicolons inside. Commented Jul 1, 2014 at 6:43

1 Answer 1

1

You don't need var if you are in an object. Also be sure to get rid of trailing commas.

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "1800 4 charity"
    },
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "1800 I have lots of jobs"
    }
};

When dealing with JSON remember you are just creating lists of names and values.

The format is

var object = {
    nameOfProperty: value,
    nameOfAnotherProperty: value2
};

Remember you only need commas between values not at the end of the list and no semicolons within the object (because then JS thinks you're missing the rest!).

The tricky part is then objects within Objects but as you're exploring, using an object as a value is perfectly legal. So start with the innermost objects and work your way out and you shoudl be fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.