Constructors in Review - didn't actually log


#1

Below is my code. I get the green "Congratulations!" message. Except... it didn't actually log anything at all to the console. This has happened on other exercises from time to time. Does that mean that I was doing something wrong those times too?

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
var rabbit1 = new Rabbit("fluffy");
var rabbit2 = new Rabbit("happy");
var rabbit3 = new Rabbit("sleepy");
rabbit1.describemyself;
rabbit2.describemyself;
rabbit3.describemyself;


#2

I don't believe that you did anything wrong, however you wrote a function and inside that function then you logged something to the console; however, you never called the function itself and therefore it won't log that piece of information to the console because it is inside of a function. All in all, no I don't think that you did anything wrong and to log it to the console then you need to call the function first.

Hope this helped and keep up the good coding :slight_smile:


#3

it is describeMyself not describemyself :slight_smile:


#4

Most importantly, describeMyself is a function so needs to be invoked.

rabbit1.describeMyself();

#5

When I did this, it didn't work. But maybe that capital M will change things...

It's funny; I'm an English teacher, and my students think I'm really picky about "unimportant" details like punctuation. This process has made me realize that I'm not that old-fashioned in asking them to notice the small stuff.


#6

Hey, it worked! Thanks all!


#7

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