Who's in your bracket 5/30


#1


I can't work out what is wrong? I keep getting the error message: Oops, try again. It looks like james' job was not logged to the console.


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

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

james[aProperty];

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


Who's in Your Bracket? - Looks like bug to me
#2

Your code is good, I suggest refreshing your browser or resetting the code and pasting this exact thing in. Hope this works!


#3

Actually @kyleaw they're two errors in his code that will not allow him to pass the exercise. :slight_smile:

First you were supposed to set the aProperty variable to the value of job not "job" itself,

to,

var aProperty = "programmer";

Lastly you were only asked to console.log the variable and not the variable and object,

should be,

console.log(aProperty)


#4

his code still works for me, maybe a bug?


#5

Just refreshed and tried this code again. It worked! Thanks for the help!


#6

No, the instruction says to set aProperty to the property name, not the property value.


#7

Bug still present. Reloading the page clears it, as reported by others.


#8

i dont agree with you.
instruction:

set aProperty to a string of the first property in james (ie. the job property).

if you go to the hint you can see it.
What are the properties of james? Set aProperty to be the name (not value!) of the first property (in order as they are defined in the code) of james.

so it should be

var aProperty = "job";

so what is 'job'?
job is a string value and its the first property of james too.it means we can take a property name to a variable.

if you write var aProperty = "programmer"; and print the value like console.log(aProperty) then what are we learning here?do you see any connection to that object.

Instructions:

Take advantage of the ability to use variables with bracket notation.

so you have to write

console.log(james[aProperty])

we can't use dot notation here like

console.log(james.aProperty);

thats main thing we are learing here.


#9

JavaScript objects have arbitrary stings for key names.

var object = {
  a: 1,
  b: 2,
  c: 3
};
for (var key in object) {
   console.log(key, typeof(key));
}

a string
b string
c string

#12

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

I wrote the program like this and it worked.


#13

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