32. Customizing Constructors


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

```

I’m stuck on this one…

// 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 Object();
the_hobbit.pages = 320;
the_hobbit.author = "J.R.R. Tolkien";

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

I’ve gone through this a million times, I don’t get why it’s not working…

<do not remove the three backticks above>

#2

here:

var the_hobbit = new Object();

using new Object() will use the standard constructor, not the custom Book constructor.

look in this exercise if you need a syntax refresher


#4

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