Contact list 4/8 Adding properties: where is the mistake in object construction


#1


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


var friends = new Object();
//friends["name"] = "Shashibhushan";
//friends.age = 60
friends.bill = new Object();
bill["firstName"] = "Bill";
bill["lastName"] = "Gates";
bill["number"] = "(206) 555-5555";

friends.steve = new Object();
steve["firstName"] = "Steve";
steve["lastName"] = "Jobs";
steve["number'] = "(408) 555-5555";

Oops, try again. There was a problem with your syntax.
SyntaxError: Unexpected number

Replace this line with your code.


#2

You wrote ' instead of "

steve["number"] = "(408) 555-5555";


#3

... And you should also precise what is bill and what is steve... Like:

friends.bill["firstName"] = "Bill";

or

friends.bill = new Object();
bill = friends.bill;
bill["firstName"] = "Bill";

#4

Thanx. My mistake. It solved.


#5

Now, i replaced the code as follows , but it seems there is some mistake again:

var friends = new Object();

bill = friends.bill;
bill["firstName"] = "Bill";
bill["lastName"] = "Gates";
bill["number"] = "123456";
bill["address"] = [ 149, "nagar", "m.p.", 482003]
steve = friends.steve;
steve["firstName"] = "Steve";
steve["lastName"] = "JObs";
steve["number"] = "789102";
steve["adress"] = [147 , "B" , "Rourkela", 769002];


#6

here also, you have to precise that bill and steve are objects... like before... with:

friends.bill = new Object();
bill = friends.bill;
bill["firstName"] = "Bill";
bill["lastName"] = "Gates";
bill["number"] = "123456";
bill["address"] = [ 149, "nagar", "m.p.", 482003];
friends.steve = new Object();
steve = friends.steve;
steve["firstName"] = "Steve";
steve["lastName"] = "JObs";
steve["number"] = "789102";
steve["adress"] = [147 , "B" , "Rourkela", 769002];

That's also equivalent to

friends.bill = {
"firstName" : "Bill",
"lastName" : "Gates",
"number" : "123456",
"address" : [ 149, "nagar", "m.p.", 482003]
}
friends.steve = {
"firstName" : "Steve",
"lastName" : "JObs",
"number" : "789102",
"adress" : [147 , "B" , "Rourkela", 769002]
}

#7

Thanx. Tried the top one successfully. But when I tried the following:

var friends = new Object();
friends.bill = {
"firstName": "Bill",
"lastName": "Gates",
"number": "(800) 333-3333",
"address": ['HIG', 149, 'B', 'Nagar', 482003],
}
friends.steve = {
"firstName": "Steve",
"lastName": "Smith",
"number": "(800) 389-9022",
"address': [ 189, "B", "Rourkela",769005],
}

the error came:
SyntaxError: Unexpected identifier
Request you to help.


#8

Oh , I caught the syntax error in 'HIG',' B', 'NAGAR', "address'. It should be "HIG", "B"," NAGAR", "address".


#9

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