16. It's all in the Genes


#1


https://www.codecademy.com/courses/objects-ii/3/1?curriculum_id=506324b3a7dffd00020bf661#

Not sure what's wrong with this. Any help is appreciated.

// create your Animal class here
var Animal = new class(name, numLegs);
    this.name = name
    this.numLegs = numLegs


// create the sayName method for Animal
Animal.prototype.sayName = function() {
    var str = "Hi my name is" + name";



// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();

#2

There seem to be several issues with your code.

As you create your class, you forgot about the curly brackets.

Adding sayName you forgot to close the curly bracket.

Does that help? If not, please provide the error message.


#3

It still doesn't work, but the error is "SyntaxError: Unexpected token ("


#4

Unfortunately, I am not familiar with creating the new class like you did. I did it this way:

function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
};

Maybe you want to try this. Does it help? If not, please provide your updated code.


#5

After adding yours, my code looks like:

function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
};


// create the sayName method for Animal
Animal.prototype.sayName = function() {
    var str = "Hi my name is" + name";
}

// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();

#6

And you keep getting the same error message?

In your sayName method I think you must write this.name instead of name

My block here looks as follows:

Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};


#7

Now I get the error "It looks like your Animal.prototype.sayName method does not properly log to the console 'Hi my name is [name]' where [name] is the name of the Animal" with the following code:

function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
};


// create the sayName method for Animal
Animal.prototype.sayName = function() {
    var str = "Hi my name is" + this.name;
}

// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();

#8

You lack a space after "Hi my name is".
It should be "Hi my name is "


#9

Still not working...

function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
};


// create the sayName method for Animal
Animal.prototype.sayName = function() {
    var str = "Hi my name is " + this.name;
}

// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();

#10

Completed it. Had a simple console.log error.

function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
};


// create the sayName method for Animal
Animal.prototype.sayName = function() {
    console.log("Hi my name is " + this.name);
}

// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();

#12

We already discussed the missing space. It doesn't matter whether you write
console.log("Hi my name is" + " " + this.name)
or rather
console.log(Hi my name is " + this.name)


#13

oh ok. My bad, I didn't see that.


#14

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