23. More Options


#1

I can't seem to find what's wrong with my code, it keeps throwing the error, "Oops, try again. Your code threw the following error when sally's name was checked: TypeError: Cannot read property 'name' of undefined"

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 bob = new Person("Bob Smith", 30); // correct
var bob = Person("Bob Smith", 30); // wrong


#3

Not much, just the word "new" is missing when you are defining Sally and Holden as a new Person ();


#4

Thanks a bunch! :smiley: It works now.


#5

Na prática também fica assim:

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

var sally = new Person("Sally Bowles", 39);
var holden = new Person("Holden Caulfield", 16);
console.log("a espécie de sally é " + sally.species + " e a idade dela é " + 39 );
console.log("a espécie de holden é " + holden.species + " e a idade dele é " + 16 );


#6

Thank you! It's working.