4. Can I See Your References? PASSED but confusion


#1

var james = {
job: "programmer",
married: false,
sayJob: function() {
// complete this method
console.log("Hi, I work as a " + [job]);
}
};

// james' first job
james.sayJob();

// change james' job to "super programmer" here
james.job("super programmer");

// james' second job
james.sayJob();

I am pretty confused by this one.
- The code above allows me to pass the lesson but the output box reads "ReferenceError: Can't find variable: job"
-console.log does not print to the output box
- What is the point/purpose of

// james' first job
james.sayJob();

and

// james' second job
james.sayJob();

it doesn't seem to have any role in the code - as far as I understand. Is this true?

I would be very grateful for any thoughts/explanation. Thanks in advance!


#2

The thing you got thier wrong but codecademy didnt notice is @csssurfer82913 When you change a objects property the syntax is like this:


csssurfer.job = "programmer"

Not like :


#3

In this line:

console.log("Hi, I work as a " + [job]);

Why have you put [job]? It would mean an array containing only one element which is the value of variable job. Since variable job doesn't exist, you get the error - "ReferenceError: Can't find variable: job".

Note that you do have the property job, which is what you are supposed to log on the console. Remember that we refer to properties by this.propertyName. Can you now figure out how to correct your problem?

Also, the other problem has been already stated by @amanuel2 .


#4

@gaurangtandon @amanuel2 Thank you both of you!