25 Constructors in Review


Passed the exercise but I feel I wrote something incorrectly.

I got it correctly, but the console isn't printing the message (ex. I'm expecting to see "I am a happy rabbit" etc).

The only thing on the right screen:


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");



First, inside the function you have to use return not console.log:
return "I am a " + this.adjective + " rabbit";
Second, when you calling the function, you have to add the parentheses:


Thank you, macropod, for catching the parentheses mistake! I've made that one myself.

Allow me to disagree with your suggestion to use return instead of console.log inside the function. Although it is an alternative possibility, but that function was provided for us and we were not asked to modify it. So I would leave it as it is. But now we don't have to use console.log again when calling the method because it will do the printing for us.

So we can just say:
rabbit1.describeMyself(); instead of

This helped me find my bug!

Hope this helps, therepublicofkang !


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