4. Unsure what is wrong with my syntax could someone explain?

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
this.job: “super programmer”;

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

1 Like

Hi,
Review please how to assign a value to a parameter using dot-notation.
Check “Objects” and “OOP” chapter in the Glossary.

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
james.job = “super programmer”;

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

1 Like

remove semicolon after sayJob: function() in james object.

also you need to put [this.job] outside the quotation marks.

1 Like

thanks for the help. I passed by mistake by taking out part of it and somehow was okay with it but thanks for explaining what I did what wrong

you console.log in your sayJob is wrong that is all the correct way is to do this:

sayJob: function(job) {
console.log(“HI, I work as a” + " " + this.job);
}

u were mission a parameter and some quotes and pluses hope this helps

1 Like

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

// change james’ job to “super programmer” here
james.job = “super programmer”;

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

Dont see what is wrong … i get the error : Oops, try again. It looks like your sayJob() method does not properly log ‘Hi, I work as a [job]’ to the console

This gives me the green light, but gives the error: ReferenceError: Can’t find variable: job

Code:

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

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

// change james’ job to “super programmer” here
james.job = “super programmer”;

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

Hi here is the answer:

var james = {
job: “programmer”,
married: false,
sayJob: function() {
// complete this method
job=this.job;
return 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();
var james = {
job: “programmer”,
married: false,
sayJob: function() {
// complete this method
job=this.job;
return 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();

1 Like

The Solution is here:

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
james.job= “Super Programmer”;

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

1 Like

yes, but the problem is that inputting that exact code, gives the error that the console log is not working properly.

This worked for me. If it doesn’t then refresh the browser. Refreshing does actually make a difference sometimes. Take note of the space after the “a” in "Hello, I work as a " + this. job in the console.log. Without that space it got temperamental with me. Also, I tried it with sayJob: function(job) & sayJob: function() and both worked. Not sure which way is best. Hopefully this helps.

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

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

// change james’ job to “super programmer” here
james.job = “super programmer”;

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