Why is Undefined Part of the Result?


#1



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


I got the code correct. This is the result:

I am a fluffy rabbit
undefined
I am a happy rabbit
undefined
I am a sleepy rabbit
undefined

I'm wondering why 'undefined' is there?


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

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


#2

Because of console.log that you typed in the last three lines


#3

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