Who's in your bracket?


#1


https://www.codecademy.com/courses/objects-ii/0/5?curriculum_id=506324b3a7dffd00020bf661#

The followoing error occurs: Oops, try again. It looks like james' job was not logged to the console.

I am aware there is already another thread (https://discuss.codecademy.com/t/5-whos-in-your-bracket/75870/4), concerning this problem, but it is already closed and somehow the solution ( adding the line: james[aProperty]; ) will not work.

I also seem not to understand the whole idea of this dot notation vs. bracket notation.

To get the value of first property of the Object james using the dot notation I would use:
james.job;
Using the bracket notation i would write:
james["job"];

If I now create a variable with the String job I can use this variable, to get the value of the property job of the object james. In this example the variable aProperty is created. (I personally don't understand what is the advantage of having a variable instead of writing a string into the bracket notation...) Using this variable would look like this:
james[aProperty];

What am I doing wrong or missunderstanding? :weary:

Thanks already for any help/comments!

Pius


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


#2

ok apparently the other thread was not closed, and I just saw, that there is a bug and all I had to do was to refresh the page... so the code is correct...


#3

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