Who's in Your Bracket?


#1


https://www.codecademy.com/courses/objects-ii/0/5#


Oops, try again. Do you have the variable 'aProperty' between brackets?


var james = {
    job: "programmer",
    married: false
};

// set to the first property name of "james"
var aProperty = james["job"];

// print the value of the first property of "james" 
// using the variable "aProperty"
console.log([aProperty]);


#2

For

// set to the first property name of "james"
var aProperty = james["job"];

They are asking you to set the first property name so it is just "job".

In order to access that first property (and hence, be able to print it), the proper syntax would be someObj["propName"];. In your case, it is james[aProperty].

You can do it like

var aProperty = james["job"];

and have your last line be

console.log(aProperty);

but they wanted you to use james[aProperty] (hence you won't be able to pass the lesson with this but it works).


#3

Thanks for your confirmation


#4

var james = {
job: "programmer",
married: false
};

// set to the first property name of "james"
var aProperty = "job";

// print the value of the first property of "james"
// using the variable "aProperty"
console.log(james[aProperty]);

this works and no error


#5

i tried this but it is not working

It looks like james' job was not logged to the console

#6

yes, it is not working!

var james = {
    job: "programmer",
    married: false
};

// set to the first property name of "james"
var aProperty = james["job"];
//console.log(aProperty);

// print the value of the first property of "james" 
// using the variable "aProperty"
console.log(aProperty);

This also doesn't work. :worried:


#7

However, this works fine on browser console. Looks there is some bug here.


#8

You can look at my comment and @sureshtrb's solution for more clarification. I see a similar error to his.


#9

Try refreshing your page. Worked for me.


#10

It was also giving me the error of not logging to the console, but reloading the page with the exact same code worked!


#11

Guys, refresh your page.
it works for me.


#12

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