Fun with Functions


#1

**

Hello Please guys tell me what's wrong in this code

** :confused:

function Person(job, married) {
this.job = job;
this.married = married;
// add a "speak" method to Person!
var speak = new Person();
console.log("Hello!");
};

var user = new Person("Codecademy Student",false);
user.speak();

Instruction:
Add a speak method to the Person constructor. Whenever speak is called, it should print "Hello!" to the console.


#2

// add a "speak" method to Person!

how to add a method:

this.someMethod = function() {

  };

so you should do

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

#3

What's stopping you from finding out?
Have you tested your code? Does it behave as described? Identify the problem.


#4

thanks now it works :slight_smile:


#5

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