Missing ) after my argument list?


#1

My code:

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);

I personally don't see the syntax error. Can anyone be of assistance?


#2

I do see though, that I have forgotten the "+" before the person's age. Now it says it "cannot read property 'species' of undefined.

Here's my updated code:

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);


#3

you need to use new keyword to create instance of the Person object. For example:

var obj = new Object();

#4

I was just going to reply, that I fixed the code again, and came up with this (although I'm back at square 1 and still says I'm missing a ')' after my argument):

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(sally.name " species is " + this.species + " and she is " + sally.age);
console.log(holden.age " species is " + this.species + " and he is " + holden.age);

#5

should be

console.log(sally.name + ... );

#6

Oh dear -- thank you.


#7

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