0
function Course(title,instructor,level,published,views){
    this.title = title;
    this.instructor = instructor;
    this.level = level;
    this.published = published;
    this.updateViews = function() {
        return ++this.views;
    }
}

var courses = [
    new Course("A title", "A instructor", 1, true, 0)
    new Course("B title", "B instructor", 1, true, 123456)
];


console.log(courses);

The error I'm getting is

Untaught Syntaxerror: Unexpected Token New

When I use the word "new" a second time within the same object array.

(e.g. If I deleted new Course("B title", "B instructor", 1, true, 123456) line, the code works fine

What am I doing wrong here?

2
  • 2
    I think you missed a comma in your array Commented Jun 19, 2017 at 3:28
  • 1
    Voting to close, this is just a simple typo. Commented Jun 19, 2017 at 3:29

1 Answer 1

1

You missed the comma , in your array. Fix it. It should be as shown below.

function Course(title,instructor,level,published,views){
    this.title = title;
    this.instructor = instructor;
    this.level = level;
    this.published = published;
    this.updateViews = function() {
        return ++this.views;
    }
}

var courses = [
    new Course("A title", "A instructor", 1, true, 0),
    new Course("B title", "B instructor", 1, true, 123456)
];


console.log(courses);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.