Tell us what’s happening:
" Add all necessary code so the Dog
object inherits from Animal
and the Dog's
prototype
constructor is set to Dog. Then add a bark()
method to the Dog
object so that beagle
can both eat()
and bark()
. The bark()
method should print “Woof!” to the console."
I feel that when it says “Add a bark() method to the Dog’s Object” it is not very clear whether you want me to add the method to the constructor function directly or to the constructor’s prototype.
I did it, it wasn’t hard, but I feel it’s not very clear. If it’s me who misunderstands, I apologize.
Your code so far
function Animal() { }
Animal.prototype.eat = 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!");
}
// Add your code above this line
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
beagle.bark(); // Should print "Woof!"
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36
.
Challenge: Add Methods After Inheritance
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance