4. Adding properties: Don't know what to do!


#1


I don't know what I have to do can someone help? thanks!
This is my code:


var friends = new Object()
friends.steve = new Object
friends.bill = new Object


I've tried to add some stuuf but it never worked.


#2

check this link
https://discuss.codecademy.com/t/can-anyone-explain-the-syntax-of-objects-within-objects-in-both-object-literary-and-constructors/38788/2?u=rcodeman

i hope it'll make sense :slight_smile:


#3

Close. Check the line above. new Object().

You will find this to be a rather verbose approach.

friends.steve = new Object();
friends.steve.firstName = "Steve";
friends.steve.lastName = "Jobs";
friends.steve.number = "(408) 996-1010";
friends.steve.address = ['10260 Bandley Dr.','Cupertino','CA','95014'];

Using object literal syntax is much simpler to write:

var friends = {
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(408) 996-1010",
        address: ['10260 Bandley Dr.','Cupertino','CA','95014']
    },
    bill: {

    }
};

#4

I'll read it :wink: thanks anyway!


#5

I'll rewrite my code because it's indeed easyer to write it using literal syntax!!


#6

Could you help me again?
This is my code:

var friends = {
friends.steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 555-5554"
};
friends.bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5553"
};
}

and this is the error that's popin up:
Oops, try again. There was a problem with your syntax.


#7

Since these are literal properties of the friends object, we do not include the object name:

var friends = {
    steve: {

    },
    bill: {

    }
};

#8

var friends = {
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 555-5554"
};
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5553"
};
}

error: Unexpected token, problem with your syntax.
I'm really bad at this exercies it looks like :frowning:


#9

The only curly brace that should have a semi-colon following is the tast one, otherwise, `steve : {},.


#10

Thank you! Now I finally got the correct answer!! :stuck_out_tongue:


#11

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