32/33 help!


#1

help please

// 3 lines required to make harry_potter
var harry_potter = new Object();
harry_potter.pages = 350;
harry_potter.author = "J.K. Rowling";

// A custom constructor for book
function Book (pages, author) {
this.pages = pages;
this.author = author;
}

// Use our new constructor to make the_hobbit in one line


#2

what they want you to do is create a variable called the_hobbit and in that variable you store the value of a new Book object.
see that in the first line you did

var harry_potter = new Object();

you just created a general object and then in the subsequent lines you added some properties to that object like the pages and the author.

harry_potter.pages = 350;
harry_potter.author = "J.K. Rowling";

The only problem with that format is that if we had to create a 100 objects(books) with the same properties and even more(like the year published etc.) then we would have to do it this way for each of them an thats not a good idea.

so we define a function like this

function Book (pages, author) {
      this.pages = pages;
      this.author = author;
}

See this as a template for creating book object .So now all we do is write

var star_wars = new Book(5000, "George Lucas");

Now to the what the question wanted we create a variable the_hobbit

the_hobbit = new Book(1000,"Tolkien");