4/8 Contact List


#1

Neither one of the methods work for me, I have tried both (separately) but i keep getting syntax errors. can someone help me out?

this is my code:

var friends = {
bill: {
firstName: "Bill",
lastName: "Hauser",
number: "(651) 5479-000"
}
steve: {
firstName: "Steve",
lastName: "Milas",
number: "(060) 4178-893"
}
brian: {
firstName: "Brian",
lastName: "Caccichotti",
number: "(978) 322 5642"
}
william: {
firstName: "William",
lastName: "Bergstrom",
number: "(651) 744 7900"
}
};

var friends = new Object();
friends.bill = {
friends.bill.firstName = "Bill";
friends.bill.lastName = "Hauser";
friends.bill.number = 651 5479 000;
};
friends.steve = {
friends.steve.firstName = "Steve";
friends.steve.lastName = "Milas";
friends.steve.number = 06 4178893;
};
friends.brian = {
friends.brian.firstName = "Brian";
friends.brian.lastName = "Caccichotti"
friensd.brian.number = 978 322 5642;
};
friends.william = {
friends.william.firstName = "William";
friends.william.lastName = "Bergstrom";
friends.william.number = 651 744 7900;
};


#2

The first way you tried to define it is called the Object literal notation(which is the recommended way). Correct syntax for writing it by your example is

var friends = {
bill: {
firstName: "Bill",
lastName: "Hauser",
number: "(651) 5479-000"
}, //<--insert a comma here
steve: {
firstName: "Steve",
lastName: "Milas",
number: "(060) 4178-893"
} ,  //<--insert a comma here
brian: {
firstName: "Brian",
lastName: "Caccichotti",
number: "(978) 322 5642"
}, //<--insert a comma here
    william: {
    firstName: "William",
    lastName: "Bergstrom",
    number: "(651) 744 7900"
    }
};

For the second one (which is not really recommended) the correct syntax is

console.log(friends)
var friends = new Object();
friends.bill = new Object();
friends.bill.firstName = "Bill";
friends.bill.lastName = "Hauser";
friends.bill.number = 6515479000;

friends.steve = new Object();
friends.steve.firstName = "Steve";
friends.steve.lastName = "Milas";
friends.steve.number = 064178893;

friends.brian = new Object();
friends.brian.firstName = "Brian";
friends.brian.lastName = "Caccichotti";
friends.brian.number = 9783225642;

friends.william = new Object();
friends.william.firstName = "William";
friends.william.lastName = "Bergstrom";
friends.william.number = 6517447900;


console.log(friends);

#3

thanks a lot @rydan!