freeCodeCamp Challenge Guide: Use a Constructor to Create Objects

Use a Constructor to Create Objects


Problem Explanation

We saw in the last challenge how to create a constructor function. Now we can simply call this function to create a new object with the properties already defined in the constructor. Simply initialise a new variable hound calling the Dog() constructor.


Solutions

Solution 1 (Click to Show/Hide)
function Dog() {
  this.name = "Rupert";
  this.color = "brown";
  this.numLegs = 4;
}
// Add your code below this line
let hound = new Dog();
11 Likes

Please change the link to ‘Get a Hint’ in this challenge, as it is refered to https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-make-instances-of-objects-with-a-constructor-function , which “does not exist or is private”

4 Likes