# freeCodeCamp Challenge Guide: Use Prototype Properties to Reduce Duplicate Code

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-prototype-properties-to-reduce-duplicate-code/301336>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [August 3, 2019, 12:42pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-prototype-properties-to-reduce-duplicate-code/301336 "2019-08-03T12:42:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 3, 2019, 12:42pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-prototype-properties-to-reduce-duplicate-code/301336/1 "2019-08-03T12:42:50Z")

</div>

# [Use Prototype Properties to Reduce Duplicate Code](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/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.

**Example:**

```javascript
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;`

* * *

## Solutions

> **Solution 1 (Click to Show/Hide)**
>
> ```javascript
> function Dog(name) {
> this.name = name;
> }
> 
> Dog.prototype.numLegs = 4;
> 
> // Add your code above this line
> let beagle = new Dog("Snoopy");
> 
> ```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 8, 2025, 3:58pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-use-prototype-properties-to-reduce-duplicate-code/301336/2 "2025-01-08T15:58:43Z")

</div>

Closed on January 8, 2025, 3:58pm UTC


