I don't understand the console output!


#1


Here's the output console:

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

It worked but I don't understand why there're 3 lines with ''unidentified"?

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


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

var list=[rabbit1,rabbit2,rabbit3];
for (var i=0;i<3;i++){
    console.log(list[i].describeMyself());
}


#2

This happens when we console.log() the return value of a function lhat already logged out the value, and returned nothing. Hence, the return value is, undefined.


#3

oh i got it. Thank you so much :slight_smile:


#4

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