Contact list 4 adding properties


#1

Hi guys,

I have a question there are 2 ways to create an object Constructor and Literal.

at first time I've tried, and doesn't work:

// Constructor notation
var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();

friends.bill = new Object();
friends.bill = firstName = "Bill";
friends.bill = lastName = "Gates";
friends.bill = number = "(206) 555-5555";

friends.steve = new Object();
friends.steve = firstName = "Steve";
friends.steve = lastName = "Jobs";
friends.steve = number = "(207) 666-6666";


At second time works
// Constructor notation
var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555"
}
};

var friends = {
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(207) 555-5555"
}
};


This part
var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555"
}
};

var friends = {
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(207) 555-5555"
}
};

can it (the above part) be replaced to Constructor object at all? How can I do?


#2

There is a mistake in the line below as well as in other lines constructed similar.

firstName is an attribute of bill, then it should also come after a '.'


#3

Thank you for your help, but I've tried and I didn't get success.

// Constructor notation
var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();

// Constructor notation
friends.bill = new Object();
friends.bill.firstName = "Bill";
friends.bill.lastName = "Gates";
friends.bill.number = "(206) 555-5555";

var friends = {
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(207) 555-5555"
}
};

console.log(friends);

I'd like to do Bill as Constructor notation

Error:
"Ops,Try again.
Did you give each of your friends an address property?
"
Evaluates to:
{ steve: { firstName: 'Steve', lastName: 'Jobs', number: '(207) 555-5555' } }


#4

Hi,
Looks like you insert your Bill into Friends, but after that you insert Steve in the same place. Bill just gets overwritten, so try to change the order. Seems like constructor notation adds Objects to the end, whereas literal to the given place (here: beginning).


#5

Thank you very much

I'm changing to Literal notation all the code