Getting TypeError when code looks right to me


#1


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


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) {
  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
instance = new Person

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


#3

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


#4

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