Use Prototype Properties to Reduce Duplicate .Code

Use Prototype Properties to Reduce Duplicate .Code
0

#1

Tell us what’s happening:

Please I need help.

Your code so far


function Dog(name) {
  this.name = name;
  this.numLegs=2

}



// Add your code above this line
let beagle = new Dog("Snoopy");

Dog.numLegs()=function(){
return this.beagle;
}

console.log(beagle.numLegs);

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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/use-prototype-properties-to-reduce-duplicate-code


#2

You have not written any code yet. What do you need help understanding?


#3

Now my code change what is my wrong.


#4

numLegs should be a prototype property not an own property.

This is wrong.All others is right.


#5

Why are you adding all of the above? You are supposed to be adding a numLegs property to the prototype of Dog. Look at the example code where they added a numLegs property to the prototype of Bird for guidance.


#6

function Dog(name) {
this.name = name;
this.numLegs=2

}

// Add your code above this line
let beagle = new Dog(“Snoopy”);

Dog.numLegs()=function(){
return this.beagle;
}

console.log(beagle.numLegs);

This is my new code wahat can I do?


#7

Again, you should not be defining a property on the Dog function itself, you should be adding a numLegs property to the prototype of Dog.

In the example, it is assumed that Bird was defined as a function (see below):

function Bird() {
  // some other stuff could go here
}
Bird.prototype.numLegs = 2;

The second line above adds a numLegs property to the prototype of Bird.


#8

Can you explain me more easilhy?


#9

I am not sure what else to explain. What is confusing you about what I stated in my last two replies?


#10

I read again that you have write and I understand it.Thank you.