2 fun with functions Oops, try again. "Make sure you added a speak method to the Person constructor "


#1

Hi everyone
My code appears to be working but I am receiving this message "Make sure you added a speak method to the Person constructor " and cannot progress to the next lesson. As far as I can tell, I have added "speak" as a method correctly. My code is being read correctly logged to console as "Hello!" so I'm not sure not sure what needs to be done here.

function Person(job, married,speak) {
    this.job = job;
    this.married = married;
    this.speak = "Hello!";
    

}
    
    // add a "speak" method to Person!
    
    var user = new Person("Codecademy Student",false, "Hello!"); 
console.log (user.speak);

#2

this.speak needs to be a method so similar to a function.

this.speak = function() {
    console.log("Hello!")    
    }

Also, inside of your new person, you don't need

Lastly, when calling your "function" user.speak, you simply need the line, user.speak();


#3

You need add speak METHOD not PROPERTY to Person constructor:

// add a "speak" method to Person!
    this.speak = function() {
        console.log("Hello!");    
    };
...
user.speak();

#4

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