Getting TypeError when code looks right to me


The console is printing this error when I run the code: "TypeError: Cannot read property 'species' of undefined"
and I also get this message: "Oops, try again. Your code threw the following error when sally's name was checked: TypeError: Cannot read property 'name' of undefined". The code looks right to me and I'm not calling the name property on either of the Person objects, so the second message is confusing to me also.

function Person(name,age) { = 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 );

instance = new Person

The operative word is new, the operator that invokes the constructor.


Ah. Of course. Thanks, that would have taken me an hour of frustration before I noticed


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