4. Can I See Your References? - What is wrong with this?


#1

Hi,

Can someone tell me what is wrong with my code, since it seems to print the right output to the console:

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

// james' first job
james.sayJob("super programmer");

// change james' job to "super programmer" here

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


#2

Is the the sayJob function supposed to take in any argument? perhaps you should remove the arguments


#3

job" and "sayJob" are listed as object properties for james. You use one object name "job" as an argument in another object name "sayJob"

==> this should be sayJob:function() and remove "this.job = job;" (no need).

//james' first job should be print "Hi, I work as a programmer"
james.sayJob();

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

//james' second job should be print "Hi, I work as a super programmer"
james.sayJob();


#4

Why do we need to put "james.job" and not "this.job"? I did the latter and got it wrong until I saw this. Thanks.