Add Methods After Inheritance I believe Do Good

Tell us what’s happening:
Describe your issue in detail here.
I do everything correctly I take a constructor function, inherit from the super class, Dog.prototype = Object.create (Animal.prototype), then I declare the constructor of the type of the class I inherit. In addition to what Animal inherits, I want to add a behavior that is exclusive to Dog objects, perfect I did, when I try to call the eat method inherited from the Animal class, the console tells me TypeError: beagle.eat is not a function

  **Your code so far**

function Animal() { }
Animal.prototype.eat = function() { console.log("nom nom nom"); };

function Dog() { 
Dog.prototype =  Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;

}

// Only change code below this line

Dog.prototype.bark = function() {
console.log("Woof!");
}


// Only change code above this line

let beagle = new Dog();

beagle.bark();
beagle.eat();



  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Add Methods After Inheritance

Link to the challenge:

This isn’t correct. You don’t want to define these within the Dog function.

1 Like

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