Constructors in Review


#1


https://www.codecademy.com/en/courses/spencer-sandbox/3/6?curriculum_id=506324b3a7dffd00020bf661#


So after I put in my code I would get "TypeError: rabbit1.describeMyself is not a function" I just want a quick solution to my problem.


function Rabbit(adjective) {
    this.adjective = adjective;
    this.describeMyself = function() {
        console.log("I am a " + this.adjective + " rabbit");
    };
}

// now we can easily make all of our rabbits
rabbit1 = {
    adjective: "fluffy"
};
rabbit2 = {
    adjective: "happy"
};
rabbit = {
    adjective: "sleepy"
};
rabbit1.describeMyself();
rabbit2.describeMyself();
rabbit3.describeMyself();


#2

You need to use the function at the top to make your rabbits.

var rabbit1 = new Rabbit("fluffy");  this.describeMyself();

You are making rabbits without using the function, use the keyword new for this exercise.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.