23. More Options

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 = “■■■■ Sapiens”;
}

function holden(name,age,species) {
this.name = “Holden Caufield”;
this.age = 39;
this.species = “■■■■ 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!

Hey @magiccookie,

These are the problem:

[quote=“magiccookie, post:1, topic:11902”]
var sally = var holden =
[/quote]You already defined them, and it doesn’t have a value that it’s equal to.:smiley:

ok thanks! but it says give her the name ‘Sally Bowels’
but I thought I already did…

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

2 Likes

where? the syntax I’ve been learning is

function holden(name,age,species) {
this.name = “Holden Caufield”;
this.age = 16;
this.species = “■■■■ Sapiens”;
}

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

Hi there,
Does the same issue remain?

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 = "■■■■ 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