Extend Constructors to Receive Arguments

Extend Constructors to Receive Arguments
0.0 0

#1

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/


#2

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.


#3

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 .