10. Another Way to Create


#1

// Our bob object again, but made using a constructor this time
var bob = new Object();
bob.name = "Bob Smith";
bob.age = 30;
// Here is susan1, in literal notation
var susan1 = {
name: "Susan Jordan",
age: 24
};
// Make a new susan2 object, using a constructor instead
var susan2 = new Object();
susan2.name: "Susan Jordan";
susan2.age: 24;

It says its something wrong with my syntax please help!!!!


#2

Hi here

susan2.name: "Susan Jordan";
susan2.age: 24;

Try to change the : to =


#3

I've also got a problem with this unit. I feel enormously stupid because I'm sure I've overlooked some really small, important detail. That's my code down there and I get the error
"Oops, try again. Make sure susan1 and susan2 have the same name property"

// Our bob object again, but made using a constructor this time 
var bob = new Object();
bob.name = "Bob Smith";
bob.age = 30;

// Here is susan1, in literal notation
var susan1 = {
  name: "Susan Jordan",
  age: 24
};

// Make a new susan2 object, using a constructor instead
var susan2 = new Object();
    susan.name = "Susan Jordan";
    susan.age = 24;

Okay, I just solved it after trying for 15 minutes or so. Susan 2 must also be called susan1. I've gotta say, the instrucations are kinda misleading, though. It says "Use constructor notation to create susan2" so I thought it's supposed to be named susan2, especially because susan2 is written with that grey background-thingy.

So, the correct code:

// Make a new susan2 object, using a constructor instead
var susan1 = new Object();
    susan.name = "Susan Jordan";
    susan.age = 24;

#4

Yep - I agree. The instructions says to create "susan2". But it fails the task, saying the name doesn't match unless you call it "susan1".

Thanks for flagging this, thought I couldn't spell Susan when it kept saying it was wrong!


#5

I was also confused by this intro.


#6

This is a correct way

var susan2= new Object();
susan2.name = "Susan Jordan";
susan2.age = 24;


#7

That's right way, but why does console only print 24? For me it's logical that it also prints susan2 name.


#8

Thanks for telling me this I think they need to change the directions they are very misleading.....try var susan1 = new Object();{
name: "Susan Jordan";
age: 24;
} instead of var susan2 = new Object();{
name: "Susan Jordan";
age: 24;
}