25. Constructors in Review


#1

I may need some fresh eyes to look at my code. I know Codeacademy has already announced they're going to be replacing this JS course this summer, but I need to know what is wrong with my code here.

I keep getting this error code: "Oops, try again. Make sure you created rabbit1, rabbit2 and rabbit3", and I'm playing and tweaking the code, but it's not accepting it.

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

var rabbit1 = new Rabbit('fluffy');
var rabbit2 = new Rabbit('happy');
var rabbit3 = new Rabbit('sleepy');
}}

rabbit1.describeMyself();
rabbit2.describeMyself();
rabbit3.describeMyself();

Any tips/help would be much appreciated!


#2

first you make an custom object Rabbit (objects are like blueprints), then after creating the object you can create actual rabbits:

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

}}

// create actual rabbits here

your actual rabbits are part of the object Rabbit, they shouldn't be

you first have the blueprint before moving on to actual make things using this blueprint (in this case rabbits)


#3

You're absolutely right! Thank you for the concise explanation; appreciate it!


#4

#5

you're welcome :slight_smile: