Use Inheritance So You DRY : supertype.prototype is not prototype of Bear or Cat

Tell us what’s happening:
Hi everyone,
I’m quite new to programming (less than one month) so forgive me for any newbie questions on my end :slight_smile:

On exercise /javascript-algorithms-and-data-structures/object-oriented-programming/use-inheritance-so-you-dont-repeat-yourself

I was not understanding how the code would link the created supertype object Animal to the subtype objects Bear and Cat. So I checked it with the following, which returns that it is not.

console.log(Animal.prototype.isPrototypeOf(Bear)); // false

However, the code is considered correct by the exercise and I’m able to move through. What am I missing?

Your code so far

function Cat(name) { = name; 

Cat.prototype = {
  constructor: Cat,

function Bear(name) { = name; 

Bear.prototype = {
  constructor: Bear, 

function Animal() { }

Animal.prototype = {
  constructor: Animal,
  eat: function() {
    console.log("nom nom nom");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

Link to the challenge:

you are correct, Animal is not prototype of Bear
this is a small step, the next few challenges will explain how to link things and such

1 Like