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.

1 Like

@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.

1 Like

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 

function Animal() { } = function() { console.log(“nom nom nom”); };

function Dog() { }

// Add your code below this line

Dog.prototype = Object.create(Animal.prototype);

Dog.prototype.constructor = Dog;

Dog.prototype.bark = function(){console.log(“Woof!”);

}; = function(){console.log();


// Add your code above this line

let beagle = new Dog();; // Should print “nom nom nom”

beagle.bark(); // Should print “Woof!”