Its All in the Genes: Unexpected token {


#1


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


I've been trying to figure out the problem here, but for the life of me I can't find it. I keep getting the error " SyntaxError: Unexpected token {" Any help would be much appreciated. Thanks!

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


#2

check the hint:

Return to the previous lesson for help on creating your own classes. Remember how we created a Person class

How you create your own class, is not what your learned


#3

You have wrong syntax for Animal constructor. should be:

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

new Object() is using for creating object but not for creating a constructor:

var obj = new Object();
obj.name = "myObj";

#4

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