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


#1

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


#2

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


#3

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


#4

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


#5

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


#6

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


#7

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


#8

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


#9

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


#10

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


#11

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


#12

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


#14

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