23. More Options


#1

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

First line:

function Person(name,age) {
         ↑

other lines:

var sally = person("Sally Bowles", 39)
            ↑
var holden = person("Holden Caulfield", 16)
             ↑

See the problem?

You also need to make sure to include a semicolon at the end of each line:

var sally = person("Sally Bowles", 39)←
var holden = person("Holden Caulfield", 16)←

And do what @j.kienberger said- add 'new' in front of 'person' on the two lines above.


#3

you also have to type "new":

var sally = new Person("Sally Bowles", 39);


#4

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