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 trialTom McCluskey
4,623 PointsDiscrepancies 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
Geoff Parsons
11,679 PointsLooks like you just need to add parenthesis to the method call:
tom.greet();
Tom McCluskey
4,623 PointsOops, responded as an answer rather than a comment!
Tom McCluskey
4,623 PointsTom McCluskey
4,623 PointsHah! I knew it had to be something like that. Thanks a million, Geoff!