2. Fun with Functions


#1

Hey Guys,

Not to sure why but I am getting lost trying to create a Method here:

please if someone could point me in the right direction that would be awesome :smile:

My code:

function Person(job, married){
this.job = job;
this.married = married;
// add a "speak" method to Person!

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

};

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

it returns me an error of -

Oops, try again. It looks like 'Hello!' wasn't logged to the console. Make sure that you properly defined the method and that you didn't change any of the provided code.


#2

Sounds stupid, but the course is probably looking for "Hello!". You print "Hello" :wink:


#3

Hi epool,

I realise this, but how should I build this method to do so?

any tips?


#4

Hi, just put a ! behind your Hello and I guess it'll work... Your method looks fine.


#5

function Person(job, married) {
this.job = job;
this.married = married;
// add a "speak" method to Person!

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

};
}

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