Reset an Inherited Constructor Property-no : after constructor

Tell us what’s happening:

// running test
Cannot read property ‘constructor’ of undefined
Cannot read property ‘constructor’ of undefined
Cannot read property ‘constructor’ of undefined
Cannot read property ‘constructor’ of undefined
// tests completed

Your code so far


function Animal() { }
function Bird() { }
function Dog() { }

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

// Add your code below this line

beagle.constructor

let duck = new Bird();
duck.constructor // function Bird(){...}
let beagle = new Dog();
beagle.constructor // function Bird(){...}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/reset-an-inherited-constructor-property

you are given this example

Bird.prototype.constructor = Bird;

Just follow the example and you will have the correct answer.

You have a bit too much code right now…

If you read the code above yours, you will see that:

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

So these two lines mean that if you make a new Bird or Dog you will actually get ‘Animal’ constructor but you want them to give Bird and Dog constructors instead, respectively. (which is achieved by the sample code shown above)

The sample code therefore gives you the answer for what you need to do for ‘Bird’. Just copy it in.
And make a new line for Dog exactly like it and you’re done.