5/10. Keep getting "Do you have aProperty between brackets


#1

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

// set to the first property name of "james"
var aProperty = james['job'];
//I have tried a couple different ways of doing this but keep geting it wrong
// print the value of the first property of "james"
// using the variable "aProperty"
console.log(aProperty);


#2

Hi you should do it like that

var aProperty = 'job'

And print it like that

console.log(james[aProperty])

#3

What´s the problem?

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

// iguale a primeira propriedade de "james"
var aProperty = 'job';

// exiba o valor da primeira propriedade de "james"
// usando a variavel "aProperty"
console.log(james[aProperty]);


#4

Hi I can't see what's wrong can you post the error you get?
Or
Try to refresh the page.


#5

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

// iguale a primeira propriedade de "james"
var aProperty = 'job';

// exiba o valor da primeira propriedade de "james"
// usando a variavel "aProperty"
console.log(james[aProperty]);


#6

Sorry to post on something so old, but I don't understand why we don't need to set var aProperty to "james[job]". Isn't aProperty a global variable since it's created outside the object james? If we had multiple objects with "job" properties, how would it know which object to take the "job" property from? :worried:

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]);


#7

Hi you right its better to create a var and and set it equal to "james[job]" but in this lesson they want you to use this form.
like you say how will we doing if there were more object with the propriety 'job'?
In this case it will be better to use this this form.

var aProperty = james["job"];

#8

I didn't realize that we could assign the value of the object property to a variable outside of the object without referring to the property through the object. Thanks for the clarification!


#9

What's wrong with my code?

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]);


#10

Update: passed by refresh the page.