Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Object-Oriented JavaScript Object Basics Creating Object Literals

add an empty method to the object literal called play.

I cannot understand how to do the second part to this challenge.

const player1 = { name: 'your Name' , color: 'your Color', isTurn :true}

1 Answer

Hi Alana, In second task all you have to do is to use dot notation to add a method called play. You can use dot notation to access any property of an object or add new property to an object. Look at the code below - all I'm doing here is that I'm using dot notation to add method (that's how we call functions that are properties to objects) called play. It's just an empty arrow function. If you are not sure what an arrow function is look at examples here: https://www.w3schools.com/js/js_arrow_function.asp

const player1 = {
  name: 'AnyName',
  color: 'anyColor',
  isTurn: true

player1.play = () => {};