23/33 - Undefined is not an object:


#1

Hey everyone, so I'm receiving the message: "TypeError: undefined is not an object (evaluating 'sally.species')"

for this code:

function Person(name,age) {
this.name = name;
this.age = age;
this.species = "Homo Sapiens";
}

var sally = Person("Sally Bowles", 39);
var holden = Person("Holden Caulfield", 16);

console.log("sally's species is " + sally.species + " and she is " + sally.age );

console.log("holden's species is " + holden.species + " and he is " + holden.age);


#2

var sally = Person("Sally Bowles", 39);
var holden = Person("Holden Caulfield", 16);

I believe when initiating a variable to an object you need the "new" Object keyword.

var sally = new Person("Sally Bowles", 39);
             ^
var holden = new Person("Holden Caulfield", 16);
              ^

#3

Ugh that was it! So simple, but I completely forgot about that part. Thank you so much lolman!