Own properties and instance of

Tell us what’s happening:
Describe your issue in detail here.
duck and beagle are instance of Animal in this code but how can I add own properties each one (for example: the name)???

  **Your code so far**

function Animal() { }

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

function Bird(name){
this.name = name;

// Only change code below this line

let duck = Object.create(Animal.prototype); // Change this line
let beagle = Object.create(Animal.prototype); // Change this line

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36

Challenge: Inherit Behaviors from a Supertype

Link to the challenge:

duck and beagle are simply objects. Regardless of their prototypes, they’re objects.

How do you add a property to an object?

If your question is “how can i make duck a descendant of both Bird and Animal,” that’s a different sort of question. First, you’d need to tell Bird that it’s an Animal (extend that class in a specialized case), and then tell duck it’s a Bird (that it should use the Bird as its prototype, and Bird should use Animal as its). Thus, duck could use the Bird constructor, setting a name property, and Bird would reference the Animal constructor, giving access to both.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.