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 trialAaron HARPT
19,845 PointsJavaScript code challenge
I am having trouble with the following code challenge:
Create a method on the contact object called fullName, use the programming from the printFullName function.
function printFullName() {
var firstName = "Andrew";
var lastName = "Chalkley";
console.log(firstName + " " + lastName);
}
var contact = {
fullName: "Andrew Chalkley"
}
4 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHi Aaron, What the challenge wants is for you to basically move the code from above INTO the 'contact' object. By doing so and using the name fullName... fullName now becomes the method for the contact object.
var contact = {
fullName: function printFullName() {
var firstName = "Andrew";
var lastName = "Chalkley";
console.log(firstName + " " + lastName);
}
}
You are adding a method to a object. If it's still unclear, I'd recommend just re-watching the video right before the challenge, where Andrew explains it.
Keep Coding! :)
Myles Cameron
2,225 PointsYou can get rid of the last variable
var contact = { fullName: "Andrew Chalkley" }
and then just run the function like so:
printFullName();
I believe that's the answer the task is looking for. Does this make sense, or would you like me to try and explain it in more detail?
Ian Polatka
12,102 PointsCopy and paste the printFullName function into the contact object. Then make it an anonymous function by removing the function name "printFullName".
var contact = {
fullName: function () {
var firstName = "Andrew";
var lastName = "Chalkley";
console.log(firstName + " " + lastName);
}
}
Jason Smith
145 PointsThe questions make no sense, please rephrase them so they can actually make sense to someone trying to learn JS face palm -_-
Patrice Nko'o
Courses Plus Student 50,511 PointsPatrice Nko'o
Courses Plus Student 50,511 PointsThanks Jason, your advice helps me ;-)