Lesson 2 Fun With Functions


#1

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

That's what alert says:
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.

I didn't get what is wrong with my code.


#2

@designpro95498,

Maybe....

++++ reset of session *****************
As you are manipulating with objects
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom


#3

ANGRY!!! Angry !!!! Angry !!!! !!! i can't got - why my ### code dont working !!!!!


#4

@cm90,
If you could display the code you are using
mentioning the Oops- or Error message you are getting ????


#5

It looks like it didnt run because you have one of your last semi colons in the wrong place. This code worked for me.

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


#6

I have a similar code, that i get error message for:

function Person(job, married) {
this.job = job;
this.married = married;
}

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

};

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

error message: Oops, try again. Make sure you added a speak method to the Person constructor


#7

because your speak function should be within the person function. Right now it is associated by itself rather than within the person function which is why you have the error


#8

you did not add speak to the person function


#9

refreshing worked for me! Thanks