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 trialStephan Hoeksema
16,567 PointsAdd an empty method to the object literal called play(). WHat do you mean? player1.play()???
Do you want to insert an method to the object?
const player1 = {
name: 'Jip',
color: 'GreyishBrown',
isTurn: true
}
player1.play()
10 Answers
Andreas Nyström
8,887 PointsHi.
To do this you want to put the function inside the object literal. With the property of play and then a function as value. If you don't get it after you complete it, rewatch the video again.
const player1 = {
name: 'NameHere',
color: 'ColorHere',
isTurn: true,
play: function(){}
}
Seth Johnson
15,200 PointsThe wording of these instructions isn't very well done, or it's a deliberate misdirection, I'm not quite sure which. Also, apparently trying to put an arrow function (which I thought was encouraged as per all of the ES2015 videos?!) doesn't work either. : /
Gabriel C. Cavallo
4,438 PointsI agree
Caleb Spindler
11,397 Pointsplay: function(){}
That does the trick! The brackets after "play" in the question made me a little confused at first. After rewatching the video, I realized that she said, "The property key is the name of the method, and that's the name you'll use when you want to call it."
In the end, one is able to create a method, e.g., play(), by using the method's name as an object property.
Jason Costa
8,823 PointsI found this quite difficult as well. The instructions were a little misleading for a student.
af09
10,704 PointsInside the object literal add the play method
const player1 = {
name: 'Jip',
color: 'GreyishBrown',
isTurn: true,
//play method
}
Salwa Elmohandes
Full Stack JavaScript Techdegree Graduate 20,240 Pointsplayer1.play=" ";
tomaszfurmanczyk
Full Stack JavaScript Techdegree Student 18,242 PointsYes, the instructor poorly conveyed the following detail of creating a empty method ---> and directing it to an OBJECT LITERAL named PLAY()
This is correct way of creating your object literal and assigning it to a variable player1.
var player1 = {
name: 'Walter Driver', color: 'Green', isTurn: true,
play: function(){} // This portion was poorly explained and the question was not as clear on what it was asking }
Jasper Kop
10,423 Pointshow could I know the answer for this question?
Dheerendra Singh
2,390 Pointsconst player1 = { name : 'abhinav', color: 'Dark', isTurn: true, play: function (player1) {}
}
Rana Dugal
9,506 Pointsconst player1 = { name: 'rana', color: 'brown', isTurn: true, play: function() { } }