11/17 what am i ding wrong


#1

var myObj["name"] = {
name: 'Lock',
age: 21
};

var emptyObj = {};


#2

Well, you mixed two different syntaxes for object creation and you should create object me, not myObj.

In this exercise you have to use the constructor (var me = new Object()), but you can still use two different notations for properties definition.

Brackets notation

var me = new Object();
me['name'] = 'Lock';
me['age'] = 21;

Dot notation

var me = new Object();
me.name = 'Lock';
me.age = 21;

#3

var me = new Object();
me.name = 'Pradeep';
me.age = 22;

When I save and submit this code, in output it only shows my age not name? can you please help me..

Thanks in advance.

Regards,
Pradeep.


#4

Hello :smile:

Well, you should not worry about that. Codecademy environment prints to the console returned value of the last evaluated statement.

Try to run this code:

var me = new Object();
me.age = 22;
me.name = 'Pradeep';
2 + 2;

Do you see? It returns 4, because this is the result of the last statement.

If you want to print something to the console in the real environment you have to use console.log:

var me = new Object();
me.age = 22;
me.name = 'Pradeep';
console.log(me.age, me.name);

#5

Thank you so much... really appreciated...


#6

You're very welcome :wink: