What are Objects For? -constructor object


#1

Hello All,

I have been going around and around with this for hours. I feel like I'm wasting my time.
It wants me to make a new object, spencer2, with the same properties as spencer but using constructor notation and the Object constructor.
Below is what I have and it keeps returning the error "Make sure to use constructor object". Where am I going wrong?

var spencer = {
age: 22,
country: "United States"
};

// make spencer2 here with constructor notation
var person = function(age, country) {
this.age = age;
this.country = age; };

var spencer2 = new person(22, "United States");


#2

I think there's not much to say lol, but I can't post with an empty text so here's my rant.


#3

even when I have it as:

// make spencer2 here with constructor notation
var person = function(age, country) {
this.age = age;
this.country = age };

var spencer2 = new person(22, "United States");

I am still getting the same error. I have went round and round changing these things trying to figure out what's wrong.


#4

Oh, it's not the semicolon, you're assigning this.country to the age parameter! Use country. ^^


#5

Sorry I know it appears that I'm sloppy. It's because Ive had this thing in so many forms possible trying to get through. The country was also stupid on my part. However, I am still getting the error:

var person = function(age, country) {
this.age = age;
this.country = country };

var spencer2 = new person(22, "United States");


#6

Ok, this question was just not clear I guess. I now realize that they want you to utilize the data already provided in your new object without hardcoding it.

Answer has been found as:
var spencer2 = new Object();
spencer2.age = spencer.age;
spencer2.country = spencer.country;


#7

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