Add Methods After Inheritance

Add Methods After Inheritance


I guess, this solution should be right… ? But it is not being accepted.
Any clue?

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


Can you add the link to the challenge here?


Sure, sorry!


Look at the example in the challenge instructions where the fly method was added. That is the correct syntax. The 3rd line of your code redefines the Dog prototype, so it is no longer inheriting from Animal, so it no longer has access to the eat method. Another issue with your code is that the bark function does not console.log the correct string.


@RandellDawson, Yes I brought that to work following the syntax in the example.
I was just wondering if the syntax shown in the link below would also work:


Yes, you could have, but you would have been missing the eat prototype method which was inherited from Animal.


Completely understood now. Thanks again!


3 posts were split to a new topic: JavaScript Add Methods After Inheritance challenge


I think below code will pass your all the test cases

Dog.prototype = Object.create(Animal.prototype);//Dog inherit eat property from animal
Dog.prototype.constructor = Dog;
Dog.prototype.bark = function(){
}//Bark property