Someone Help me ! whats wrong with my code?!


#1

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

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

var holden = new Person("Holden Caulfield", 16);
holden.name("Holden Caulfield");
holden.age(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

Hi,

The issue you're having is to do with the way you're creating sally and holden objects.

var sally = new Person("Sally Bowles", 39);
var holden = new Person("Holden Caulfield", 16)

The above two lines are already both calling the Person constructor and this in turn is creating two objects with a name, age and species properties for each.

There is no need to then specify the likes of:
sally.name("Sally Bowles");
sally.age(39);

or

holden.name("Holden Caulfield");
holden.age(16);

If you remove those lines from your code you'll find that it executes just fine.


#3

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

var sally =
sally.name("Sally Bowles");
sally.age(39);

var holden =
holden.name("Holden Caulfield");
holden.age(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 );


#4

I have it like this now but it still does not wrong so what should I remove please


#5

Hi there,

As mentioned previously, you're already calling the Person constructor and creating the two objects necessary with the following lines of code:

var sally = new Person("Sally Bowles", 39);
var holden = new Person("Holden Caulfield", 16)

You do not need to then call:
sally.name("Sally Bowles");
sally.age(39);

and

holden.name("Holden Caulfield");
holden.age(16);

If you correct this in your original code, you should end up with the following:

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

With that you should be able to console.log what you're after!