Can I see your references? Passed but incorrect output


#1

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

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

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

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


#2

ReferenceError: job is not defined


#3

In the function body, you do not need to put this.job = job, that part comes when you are dealing with Object constructor. And also, you have to console.log this.job not james.job. Fix these two little things up... and you'll be good to go :smile:!


#4

Output gives, " Hi, I work as a programmer."
Still gives error: job is not defined


#5

I forgot to add one thing to my original post. To make james have a new job, you have to change the job of james by using either dot notation james.job or by square bracket notation james["job"]. Fix this last one thing, and you'll be good to go!


#6

The first output is obtained, for the 2nd one it now says TypeError: james.job is not a constructor.
Here is the code-

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

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

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

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


#7

You don't need to use the new keyword, @dataninja43387


#8

Sorry to trouble you again, but now it says james.job is not a function.
Still gives the first output though. If you could just explain why it is happening and what should happen instead, that would be great.
Thank you for your time.


#9

Okay, @dataninja43387, to set an existing property of an Object to something else you must use one of two types of notations

 object.prop = "New Property"
           //or
 object["prop"] = "New Property"

I am not allowed to explicitly give you the code because it is against Codecademy guidelines, which all of us are supposed to follow. Sorry for the inconvenience @dataninja43387. Hope this clears things out...


#10

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