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

JavaScript Prototype Lesson-Function returns the actual function instead of the intended console log.

I'm using the exact same code as the lesson here and when I call the function using jim.greet I actually get the code from the function instead of the console.log output. Any ideas on what is going on.

ar personProtoype = { // 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 Sapien', // };

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

// Person.prototype = personProtoype

// jim = new Person("Jim");

Oupt on the console

jim.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!");} functions.js:61

Monkey D Luffy can u repost ur code, or use jsfiddle.com to show code Im not able to read through.

1 Answer

Brandon Flade
Brandon Flade
2,769 Points

Hi Monkey D Luffy ,

It looks like you are referencing the function vs. actually calling it. If you call jim.greet("Monkey","Amazing"); you should get Hello, Monkey I am Jim and I am in a Amazing mood!