16/30 It's All in the Genes


#1

I have an 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 and can't get what's wrong. Help!
Here is 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 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();

#2

@julia_wilson,

Your console.log() argument should either be

("Hi my name is"+" " +this.name);

or

("Hi my name is "+this.name);

Only 1 space between is and this.name


#3

Thanks a lot! :slightly_smiling:


#4
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]);
}

#5

I'm using this code:

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

The name appears in the log, but I'm getting an error message that says:

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

If it is appearing in the log, why am I still getting this error message?


#6

get rid of the comma and try again.