Who's in Your Bracket? 5/30


#1

Here is 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])

And here is the error i am getting:

Oops, try again. It looks like james' job was not logged to the console.

I don't get why it's not working, can anyone help?


#2

@markus.k,
You might want to do a refresh Browser....

++++ reset of session *****************
As you are manipulating with objects
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom


#3

It would also seem that you're missing semicolons after your aProperty declaration and console.log statements.


#4

Semicolons haven't had an effect so far in my course so that's probably not a problem


#5

So if i am working with objects and at one point the code doesn't work but looks right then a single refresh is gonna solve that.

Thanks!


#6

@markus.k,
It is not only when working with object....Always do it....


#7

Okay, Thanks again :slightly_smiling:


#8

That is true - in Javascript, semicolons are optional after statements separated by line breaks, but I like to remind people as it's good practice for consistency (especially with other languages where semicolons are necessary after statements, such as PHP).

But I was a little off-topic there, apologies!


#9

Not a problem.
Appreciate your help!


#10

@markus.k,
@nedwards,

== discussions / opinions ==
javascript when to use semicolon site:stackoverflow.com
http://stackoverflow.com/questions/444080/do-you-recommend-using-semicolons-after-every-statement-in-javascript


#11

if someone doesn't know how to code it:

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"

var aProperty = "job";
console.log(james[aProperty]);


#12

this code worked for me:


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