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().

Ive tried the different ways to add a function but its not working. Please help

object.js
const player1 = {
  name: 'adil',
  color: 'blue',
  isTurn: true
   function: play()
}

2 Answers

Hi Adil, you are trying to set property inside an object. 'function' cant be a property name, as this is reserved word in Javascript environment.

Try this instead:

const player1 = {
  name: 'adil',
  color: 'blue',
  isTurn: true,
  lestPlay: function() {
    play()
  }
}

I also tried a variation like that after I posted this question but it still doesnt work and I tried yours but nope

Hi Adil, now I have checked the challenge:

try this:

const player1 = {
  name: 'adil',
  color: 'blue',
  isTurn: true,
  play: function() {}
}