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(){
console.log("Grrrr!");
}
};
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(){
console.log("Grrrr!");
}
};
Can you add the link to the challenge here?
@camperextraordinaire, 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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/change-the-prototype-to-a-new-object
Completely understood now. Thanks again!
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(){
console.log("Woof");
}//Bark property
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!”);
};
Dog.prototype.eat = function(){console.log();
};
// Add your code above this line
let beagle = new Dog();
beagle.eat(); // Should print “nom nom nom”
beagle.bark(); // Should print “Woof!”