Sally and Holden are confusing


#1

Not sure what I'm doing here. help?? :frowning:

Code:

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

function sally(name,age) {
sally.name = "Sally Bowles";
sally.age = 39;
sally.species = sally.species;
}
function holden(name,age) {
holden.name = "Holden Caulfield";
holden.age = 39;
holden.species = holden.species;
}
console.log("sally's species is " + sally.species + " and she is " + sally.age + " years old.");
console.log("holden's species is " + holden.species + " and he is " + holden.age + " years old.");

Error Message:

Make sure to give sally the name 'Sally Bowles' (but i think there are more errors beyond that)

Instruction:

Create a new object called sally using the Person constructor. Her name is "Sally Bowles" and she is 39. Create another object called holden. His name is "Holden Caulfield" and he is 16.

Edit the sentence printed out such that it includes the age of sally and holden respectively.

Thanks in advance!


#2

I think to create an object you need to use `var my_object = ...
In your code you use function instead of var, and your objects have braces with parameters like (name , age) that shouldn't be there.

I think what you did is make new classes instead of creating objects.


#3

I removed the function part of the code, and this is what I came up with.

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

var holden = new Object();
holden.name = "Holden Caulfield";
holden.age = 39;
holden.species = holden.species;

but now I got this error message:

Make sure to use the Person constructor when creating sally


#4

You created new instances of Object not Person.

var holden = new Person();


#5

Thanks, got it now. much appreciated


#6

thanks .that's great :smile:


#7

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