23. More Options


#1

I do not know what is wrong with my code, I have revised it multiple times and changed it, can someone please tell me what's wrong with it and how this type of code works? Here's the code:

function sally(name,age,species) {
this.name = "Sally Bowles";
this.age = 39;
this.species = "Homo Sapiens";
}

function holden(name,age,species) {
this.name = "Holden Caufield";
this.age = 39;
this.species = "Homo Sapiens";
}

var sally =
var holden =
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);

thanks in advance!


#2

Hey @magiccookie,

These are the problem:

You already defined them, and it doesn't have a value that it's equal to.:smiley:


#3

ok thanks! but it says give her the name 'Sally Bowels'
but I thought I already did...


#4

You need to use the objects function

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


#5

where? the syntax I've been learning is

function holden(name,age,species) {
this.name = "Holden Caufield";
this.age = 16;
this.species = "Homo Sapiens";
}

so what do I need here based on the code I gave earlier?


#6

Hi there,
Does the same issue remain?


#7

Therefore, no need to rewrite the object again by using function ...etc
just directly after the var sally = new Person ()

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

//Creating an object with Person constructor it is like using the older objects with new word modifications