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 Filling Out the Play Method

William Tunna
William Tunna
2,946 Points

Don't understand what I'm doing incorrectly here

I've been trying to figure out what I'm doing wrong here. I'm using the dot notation as asked, and creating a function to test if it's the player ones turn

object.js
const player1 = {
    name: 'Ashley',
    color: 'purple',
    isTurn: true,
    play: function() {
        if (player1.isTurn) {

    }
    }
}

1 Answer

Hi, William, let us breakdown the problem:

The first task is that we need to do an if statement that will execute if the isTurn property of the object if true. The reason why your code is not working is that the challenge ask you to access the isTurn by dot notation and using the this keyword.

Here is my code:

const player1 = {
    name: 'Ashley',
    color: 'purple',
    isTurn: true,
    play: function(){
        // write code here.

      //Using the this keyword to refer to the current object
      if(this.isTurn){

      }

}

If that helped you, please mark as best answer to indicate other students your issue is resolved!