Prototype function

i did exactly like the example, this somehow doesnt work

Your code so far

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(){

// Add your code above this line

let beagle = new Dog();; // 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/68.0.3440.106 Safari/537.36.

Link to the challenge:

You’re almost there. Notice that in the example, the constructor function definition is self-contained:

function Animal() { }

The prototype definitions come after.

But in yours you’ve put the prototype definitions inside the constructor function.

When I change that, your solution passes.

1 Like