Adding your friends


#1

var friends = new Object;

friends.name = "Bill";
friends.number = 8 (555) 555-55-55;

var friends2 = new Object;

friends2.name = "Steave";
friends2.number = 8 (555) 666-55-55;

SyntaxError: missing before statement
What is wrong?


#2

Hi the leeson ask you to create a friends object and inside it you should add the bill and steve object ...
Do you see now how it should be?


#3

No, I do not understand how to do it

This code does not work

var friends = new Object();

friends.bill = new Object();
friends.steave = new Object();

friends.bill = {};
friends.steave = {};


#4

Here an example. ..
Create a human object and inside It You create two object man And woman...
You Can do It in two Way
First One

var human = new Object();

Human.man = new Object();
Human.man.firstName = "Ben"

Human.woman = new Object();
Human.woman.firstName = "elena";

Or You Can do It like that

var  human = {
    man : {
       firstName: "ben",
   },
   woman: {
       firstName: "elena",
   },
},

#5

Excuse me for not understanding, I try to understand :sweat:

But my code for your example does not work

Am I doing something wrong?

var friends = new Object();

friends.bill = new Object();
friends.bill.name = "Bill";

friends.steave = new Object();
friends.steave.name = "Steave";

Oops, try again.
Did you add steve to the friends object?

Can I find it easier to understand how Object literal than Object constructor ..

Also not working// :confounded:

var friends = {};

friends.bill = {
firstName: "Bill",
lastName: "Gates",
};

friends.steave = {
firstName: "Steve",
lastName: "Jobs",
};

Oops, try again.
Did you add steve to the friends object?


#6

look well the error you get
Oops, try again. Did you add steve to the friends object?
here

friends.steave = new Object();
friends.steave.name = "Steave";

you wrote steave instead of steve


#7

Yes, it works! Thank you very much for the detailed help! :grinning:


#8

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