23/33


#1

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

var sally = new Object();{
this.name = "Sally Bowles";
this.age=39;
this.species = "Homo Sapiens";
}
var holden = new Object();{
this.name = "Holden Caulfield";
this.age = 16;
this.species = "Homo Sapiens";
}
console.log("sally's species is " + this.species + " and she is " + 39);
console.log("holden's species is " + this.species + " and he is " + 16);

what is error


#2

Hey @courserunner12901! Your way of creating objects is not correct. Create the objects like this:

var holden = {
name = "Holden Caulfield";
age = 16;
species = "Homo Sapiens";
}

#3

but the problem specifically calls for using the 'Person' constructor in creating the defining parameters for person sally, and person holden.


#4

Hey there! I ran into the same problem what you have to do is code:
var holden = new Person (parameters) and same with sally, this way you are defining the parameters using the Person Constructor (the function at the top of the page), the problem was when you are using "new Object" you are already defining the parameters without using the Person Constructor.


#5

In the starting of the code you should write
function Person(name,age,species)
try it and then put your question if you need help.....


#6

I thought the lesson wanted us to write the code this way...

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

console.log("sally's species is " + sally.species + " and she is " + sally.age);


#7

Im Preety sure your suppose to write it in object literal notation


#8

@amanuel2

Hi,

I have since completed that task for this unit lesson now as I too was unsure which way to write the code and I managed to succeed by following the Constructor Notation, where we use the keyword new.

so it seems for that part of the task it wasn't asking for us to write the Literal Notation, where we use var Name = { };

when we get to exercise 30, we review both ways to make objects again and for that task we also write up Constructor Notation, where we use the keyword new.

Its good that we are being taught the two different ways and will hopefully come to understand which format may be the best one to use depending upon what task is at hand, but for this exercise itself it seems the Constructor Notation works best for this exercise and exercise 30.


#9

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

console.log("sally's name is " + sally.name + " and she is " + sally.age);
console.log("holden's name is " + holden.name + " and he is " + holden.age);


#10

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

**** You must keyword "new" before Object
Exam var sally =new Person("Sally Bowles",39);


#11

This worked for me:

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


#12

Thats what worked for me