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 trialGiuseppe Nardella
17,790 PointsHow can I pass parameters to greet function?
Is there a way to pass parameters to greet function?
2 Answers
Marcus Parsons
15,719 PointsHey Giuseppe Nardella,
I'm not sure if you're asking whether you can send parameters to the greet functions, or whether you can set your own parameters with the greet function. The question is a bit unclear, so no worries, I'll just go over both.
The greet function itself takes the parameters name
and mood
. All you have to do is call the greet function after you make a new person:
var giuseppe = new Person("Giuseppe");
//Will output to console: Hello, Giuseppe. I am Giuseppe, and I am in a happy mood!
giuseppe.greet(giuseppe.name, "happy");
You can also override the prototype of person if you wish to pass in different arguments to the greet function per person. Let's say you just want to get the name of one person:
var giuseppe = new Person("Giuseppe");
//Override the greet function set in prototype
giuseppe.greet = function (name) {
console.log("Hi, "+name+"! Welcome back!");
};
//Will output to console: Hi, Giuseppe! Welcome back!
giuseppe.greet(giuseppe.name);
Does that answer your question?
Giuseppe Nardella
17,790 PointsThanks. It's all clear.
Marcus Parsons
15,719 PointsYou're absolutely welcome, Giuseppe. Happy coding, my friend!