Extend Constructors to Receive Arguments

Tell us what’s happening:

Your code so far


function Dog(name, color) {
this.name = "Doggy";
this.color= "white";
this.numLegs = 4;
}
let terrier = new Dog("Tommy", "black");

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/extend-constructors-to-receive-arguments/

1 Like

Your function is not flexible at all. Your code says that every Dog object is called Doggy and is white with four legs. The instructions did not say that you should set the name or colour. What they want is for you to learn how to read the parameters you got and use them. The instructions give you the following example:

function Bird(name, color) {
  this.name = name;
  this.color = color;
  this.numLegs = 2;
} 

Notice how the name and color are function inputs and are used to define the new Bird? Just do the same thing in your Dog function.

2 Likes

yeah ,because they want from us to have the possibility fro creating more objects have common chracteristics with different values, therefore we can use parameters in the new object to acheive that .

1 Like

They need to fix this lesson, maybe change it to something like this instead…

function Bird(name, color) {
  this.birdName = name;
  this.birdColor = color;
  this.numLegs = 2;
} 

so new people don’t get confused

1 Like

What about

function Bird(input1, input2) {
  this.name = input1;
  this.color = input2;
  this.numLegs = 2;
} 

maybe just more clarification on the lesson itself, as i got very confused as to what my goal was

1 Like

You have told your “Dog” function to accept parameters (name, color) then passed two of them inside of the same function, which doesn’t work. You just need to tell your function “this.name” is going to be a name that is passed when assigning terrier as a new constructor and passing a new name and color to it. I don’t know if that makes sense or not. All you have to do is make the “this.name” inside of your function and " this.color" general (this.name = name;) and (this.color = color; so they can accept whatever is passed throug “let terrier = new Dog(“Tommy”, “black”);” which is Tommy and Black. I hope that made sense. I had to think about it for a while myself. lol