30. Spencer/Spencer2 age bug?


#1

As you can see this is the answer adopted by me and every other post I found on the Q&A.

var spencer2 = new Object();
spencer2.age = 22;
spencer2.country = "United States";

Despite my best efforts I keep getting the message about the un-matching ages and as of yet have found no solution. I have also soured the Q&A for answers but when I tried everyone else's code it managed not to function.

Thanks in advance.


#2

@gigaace77334

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

var spencer2 = new Object();
spencer2.age = 22;
spencer2.country = "United States";


#3

Thanks @ankurlvv . Got it working now.


#4

Sorry, but what the difference?


#5

I agree with chiffka....I don't see anything wrong with the original post? What was the problem? Out of curiosity sake...


#6

I have no idea. but it worked somehow.


#7

I had the exact same answer but it kept telling me "Make sure to use the Object constructor". Finally I pasted in a copy of the code from this thread and it worked.

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

var spencer2 = new Object();
spencer2.age = 22;
spencer2.country = "United States";

Super weird.


#8

In my case I found that mistake was in spase after Object before (


#9

Hi all, this worked for me,

var spencer2 = new Object();

spencer2.age = spencer.age;
spencer2.country = spencer.country;


#10

there was nothing wrong with @gigaace77334 code i copied it and it ran perfect as it was same as i wrote one for myself


#11

I ran into the same issues. I was using a function and "this.age" to create the object. They wanted a single object creation.
//INCORRECT SYNTAX
var spencer2 = new Object() {
this.age = 22;
this.country = "United States";
};
//CORRECT SYNTAX
var spencer2 = new Object();
spencer2.age = 22;
spencer2.country = "United States";


#12

Stormzy is the problem #problem