I create an object and I continue to receive an unexpected token of error message: this is when I add a method. Here is my code.
function Person(name,age,gender,job) {
this.name = name,
this.age = age,
this.gender = gender,
this.job = job,
this.pSpeak = function() {
func.innerHTML = "My name is " + this.name + "<br>I am " this.age + "years old." + "<br>I am a " + this.gender + ".<br>My career is " + this.job +".";
}
}
var colin = new Person("Colin James",24,"man","Social Media Consultant");
I read various articles about creating methods inside objects, and I don’t see where I made a mistake here. When I remove the syntax this.from the name, age, gender, job variables in the pSpeak method, I get an unexpected identifier error.
Any suggestions on what's going on?
source
share