我正在开发 Codecademy 的 JavaScript 程序并有一个简单的分配来使用构造函数“book”创建一个新对象。我不断收到作者的错误消息,但我不明白为什么。
// 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") ;
最佳答案
根据错误消息:
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.
这意味着您只是在代码中丢失了一个点字符:
var the_hobbit = new Book(320, "J.R.R Tolkien") ;
^-- here should be an extra dot
关于javascript - 找不到 CodeCademy JavaScript 第 32/33 课的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30156767/