Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Foundations Objects Prototypes: Part 1

Discrepancies in console.log() with Prototypes: Part 1 video

Hey all,

So, I'm working on the JavaScript Foundations > Prototypes videos, and as I'm going through them I'm following along. At the end of the lesson, though, my code doesn't seem to work, while Jim's does. Here's what I've got:

var personPrototype = {
    name: 'Anonymous',
    greet: function (name, mood) {
        name = name || "You";
        mood = mood || "good";

        console.log("Hello, " + name +
                    " I am " + this.name +
                    " and I am in a " + mood + " mood!");
    },

    species: 'Homo Sapiens'
};

function Person(name) {
    this.name = name;
}

Person.prototype = personPrototype;

tom = new Person("Tom");

According to the video, I should be able to input tom.greet and have "Hello You I am Tom and I am in a good mood!" log to the console, but instead I get:

function (name, mood) {
        name = name || "You";
        mood = mood || "good";

        console.log("Hello, " + name +
                    " I am " + this.name +
                    " and I am in a " + mood + " mood!");

which seems really strange. I've looked for stray and missing semicolons and whatnot; I imagine I'm just missing one, but I'm pretty stumped.

Thanks!

2 Answers

Looks like you just need to add parenthesis to the method call:

tom.greet();

Hah! I knew it had to be something like that. Thanks a million, Geoff!

Oops, responded as an answer rather than a comment!