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 trialZach Freitag
20,341 PointsModify this object so it uses two properties firstName and lastName and remove their variable declarations
I'm confused by this question,
The videos gave a simple example of:
var dice = { // Very simple object sides: 6, roll: function () { var randomNumber = Math.floor(Math.random() * this.sides) + 1; console.log(randomNumber); } }
How should I approach this challenge?
var contact = {
fullName: function() {
var firstName = "Andrew";
var lastName = "Chalkley";
console.log(firstName + " " + lastName);
}
}
1 Answer
Steven Parker
231,275 PointsTo convert the function variables you could move them from inside the function and make them peers of "fullname" (like "sides" is to "roll" in the dice object).
The syntax for properties uses a colon instead of an equal sign to separate the names from the values, and the "var" keyword is not needed. Also, the complete property name/value pairs are separated by commas instead of semicolons.
Zach Freitag
20,341 PointsZach Freitag
20,341 PointsSo..
Steven Parker
231,275 PointsSteven Parker
231,275 PointsLooks good. That should get you past task 1.
Zach Freitag
20,341 PointsZach Freitag
20,341 PointsThanks a lot Steven!
That's the first time I've ever moved a function around. Onwards and upwards at this point!