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 trial

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.

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

1 Answer

Martin Balon
Martin Balon
43,651 Points

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 = () => {};