12-4 adding properties


#1


var friends=new Object();
    friends.steve=new Object();
        friends.steve.firstname:"Steve",
        fiends.steve.lastname:"Jobs",
        friends.steve.number:"(123)-555-5555",
    friends.bill=new Object();
        friends.bill.firstname:"Bill",
        friends.bill.lastname:"Gates",
        friends.bill.number:"(321)-555-5555",

This is the error I get
SyntaxError: Expected ';'

Please help


#2

The above is a mix of syntaxes, both constructor and literal. Let's go with the literal, only...

var friends = {
    steve: {
        firstname:"Steve",
        lastname:"Jobs",
        number:"(123)-555-5555"
    },
    bill: {
        firstname:"Bill",
        lastname:"Gates",
        number:"(321)-555-5555"
    }
}

For practice, see if you can correct the OP code to constructor syntax.


#3

Thank you. Can I ask you another question?
How would you go with constructor in this excercise?


#4

Wait I think I got it !!

var friends=new Object();
friends.steve=new Object();
friends.bill=new Object();
friends.steve.firstName="Steve";
friends.steve.lastName="Jobs";
friends.steve.number="(123)-555-5555";
friends.bill.firstName="Bill";
friends.bill.lastName="Gates";
friends.bill.number="(321)-555-5555";

The excercise tells me its correct.


#5

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