23. More Options "Cannot read property 'species' of undefined


#1

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

var sally = Person("Sally Bowles", 39);
var holden = Person("Holden Caufielf", 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);

Replace this line with your code.


#2

if you want to create a new instance of a class (in this case person) you need the new keyword:

new Person

#3

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