Introduction to Objects I – Customizing Constructors


#1

I am doing the exercise exactly like it wan't me to, only I keep on getting a reference error saying,

"Oops, try again. Make sure that the_hobbit's author is J.R.R. Tolkien by passing it as the first argument to the Book constructor."

I tried passing the author as the first argument, but that didn't make a difference. Here is my code.

// 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
var the_hobbit = new Book(320, "J.R.R Tolkien");

#2

HI this line

var the_hobbit = new Book(320, "J.R.R Tolkien");

the name of the author should be

"J.R.R. Tolkien"

with a dot after the last R


#3

LOL :slight_smile: Thanks a lot. The funny thing is that I had copied the name for Tolkien to prevent any typos and I must have not copied the dot at the end. I would have been stuck on that exercise for quite a while :slight_smile: