Use Inheritance So You Don't Repeat Yourself

Use Inheritance So You Don't Repeat Yourself
0.0 0

#1

Tell us what’s happening:

Your code so far


function Cat(name) {
  this.name = name; 
}

Cat.prototype = {
  constructor: Cat, 
  
  }
};

function Bear(name) {
  this.name = name; 
}

Bear.prototype = {
  constructor: Bear, 
  
};

function Animal() {
  
 }

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

Please let me know how to connect Animal prototype (which is universal ) with Cat and Bear

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/use-inheritance-so-you-dont-repeat-yourself/


#2

Please let me know how to connect Animal prototype (which is universal ) with Cat and Bear

It’s nothing you should worry about ( even if you got the concept :slight_smile: )^^
The test will check just if you did what you’re asked to do, nothing more ^^


#3

Hello everybody, I am a bit confused about the wording of the question.

In the example, a supertype of Bird and Dog are created, called Animal. However, I am unsure of how Animal is made the supertype of Bird and Dog. It seems like it is similar in the chain as Bird and Dog. Where is it declared explicitly that Bird and Dog are subtypes, or where does is state that Animal is the supertype?

Thank you!

EDIT Just realized that this is covered in the next two lessons.