16. It's All in the Genes


#1

I Don't Know What is the problem in my code

// create your Animal class here
function Animal(name,numLegs)
{
this.name=name;
this.numLegs=numLegs;
};

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

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


16. Its all in the genes (solution) CMIIW
#2

Try this here

// create your Animal class here
function Animal(name,numLegs)
{
    this.name=name;
    this.numLegs=numLegs;
}

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

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

or you can test it HERE


#3

you must use this.name , not just "name"


#4

Also, codecademy requires that you use improper grammar. It should be 'Hi, my name' not 'Hi my name'.


#5

I used the exact same code and nothing prints out to the console. Anticipated thanks


#6

Ok. After refreshing the page, it did output the result.


#7

You should put space between "Hi my name is " and this.name to work it properly.
You can do this: "Hi my name is " + " " + this.name


#8

The space after the is handles that


#9

Hi. My code prints correctly to the console, but I get this message saying my method does not properly log to the console. This is my code:

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


#10

I have the same problem...Does anyone have an idea?


#11

I realized I included a comma after Hi. But the author didn't specify one. This is why the console printed out the string, but did not fully accept the code. Hope that helps @jt1


#12

Thanks! That worked for me.


#13

I'm curious about this question as well since my code is similar to the author's. I have the right answer to the exercise, but why is "above string here" + name not acceptable? Is there a good reason or is Codeacademy just being finicky?


#14

Look at my code ........please help me// create your Animal class here
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();

output: Hi my name is Captain Cook.
BUT THE PROBLEM IS I'M STILL GETTING THIS ERROR MESSAGE
Oops, try again. 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
BECAUSE OF THIS ERROR ICAN'T GO FURTHER IN THIS COURSE.


#15

After refreshing my browser, this is the code I ran and it worked:

// create your Animal class here
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();


#17

Hi can anyone help when i submit it comes up with "SyntaxError: missing ) after argument list"
I've looked through it but can't seem to figure out what i'm missing i'm hoping some fresh eyes will help

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

#18

check this line you have an error there


#19

Hi my code is correct and i 'm getting the error:
Oops, try again. It looks like your Animal constructor does not take in two arguments and save them as 'this.name' and 'this.numLegs' respectively.

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


#20

Yea, I had trouble with this because I didn't have space between my this.name. Thanks for that extra comment!


#21

console.log("Hi my anme is " + name);
>>Should be console.log("Hi my name is " +this.name);