Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Console output in Javascript

Hi. I'm doing a test for school. I'm trying to create a class that returns the following output in the console.

         movie = new Movie("Lord Of The Rings");  // This is the input
          [Movie "Star Wars"]  // Expected output

Here is my code so far.

var Movie = function Movie(title) {
    this.header =  this.title = (title) ? "[Movie \"" + title + "\"]": "[Movie]";
    this.greatMethod = function(){
     // Do some cool stuff
    }

}


movie = new Movie("Lord Of The Rings"); //  [object Object]  

What am I doing wrong here? Am I missing something?

1 Answer

given what you have, maybe:

var Movie = function Movie(title) {
    this.title = (title) ? "[Movie \"" + title + "\"]": "[Movie]";
    this.greatMethod = function(){
     // Do some cool stuff
    }
    this.print = function(){
        console.log(this.title);
    }
}

movie = new Movie("Lord Of The Rings");  // This is the input
movie.print();