freeCodeCamp Challenge Guide: Use Prototype Properties to Reduce Duplicate Code

Use Prototype Properties to Reduce Duplicate Code

Problem Explanation

The prototype property allows us you to add new properties to an object constructor from outside the original code block. The prototype property also allows you to add new functions to the objects constructor. The following code demonstrates how to use .prototype on an object to create a new property in the constructor.


Obj.prototype.newProperty = "New Property!";

Using this logic, simply create a new prototype property for numLegs. The test cases can be passed by replacing the Bird object with the Dog object in the example given - Bird.prototype.numLegs = 2;


Solution 1 (Click to Show/Hide)
function Dog(name) { = name;

Dog.prototype.numLegs = 4;

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