3. Adding your Friends


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/3?curriculum_id=506324b3a7dffd00020bf661


Im practicing both ways to create objects and my last block of code does not recognize
friends[bill] = {};
Error message says that "bill is undefined" What did I miss?


/*var friends = {
    bill: {},
    steve: {},
    kai:{}
    };*/

/*var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();
friends.kai = new Object();*/


var friends = {
friends[bill] = {};
friends.steve = {};
friends.kai = {};
};


#2

Because the key must be a string:

friends['bill']

#3

Now I have syntax error "expected : "


#4

Must have changed your code. I don't see any : in your last example. My reply was just a scratch on the surface.

Consider,

var friends = {
friends[bill] = {};
friends.steve = {};
friends.kai = {};
};

The above syntax is incorrect.

var friends = {};
friends['bill'] = {};
friends.steve = {};
friends.kai = {};

The above is correct.