Introduction to Objects - 23/33(more options)


#1


https://www.codecademy.com/en/courses/spencer-sandbox/3/4?curriculum_id=506324b3a7dffd00020bf661#


I am getting an error massage that says: Make sure to give sally the name 'Sally Bowles'. And i have no idea what is wrong with my code


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

var sally = new Object("Sally Bowles",39);
var holden = new Object("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

here..

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

new Object ?
hint**

Your constructor is Person!
And using this constructor you have to create sally and holden objects!


#3

@greentreemee thank you so much. It works now :grinning:


#4

I have attempted to do this using "var sally = Person("Sally Bowles", 36)'" and will receive errors that sally.name, sally. age, and sally.species are still undefined. Why is that?


#5

if you post your code ?then that might help to debug your error


#6

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

var sally = Person("Sally Bowles", 39);
var holden = 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);

this gave me an error.

Oops, try again. Your code threw the following error when sally's name was checked: TypeError: Unable to get property 'name' of undefined or null reference

I couldn't figure out how to correct it.


#7

@wasai

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

In these two lines of code.
When we create Objects using Constructor, we use new keyword before constructor (Person)name!


#8

@crypto3301
You missed keyword new before constructor's name Person!


#9

It works now! Thank you so much!


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.