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

I don't know what I am doing

I'm not 100% certain what to do here?

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

3 Answers

Johnathan Guzman
Johnathan Guzman
7,432 Points

Hey Mark,

Just to re-iterate what Steven said, you don't need to refer to the object as it's "name"(in this case, it is player1) when working within it's scope.

Since we are working inside of it, we can refer to it as "this" and then target the desired property(for this challenge, it is "isTurn").

Below is a copy of my code:

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

        }
    }
}

I hope this helps.

Steven Parker
Steven Parker
231,275 Points

Close, but instead of using the instance name, an object should always refer to itself as "this".

Also, when testing a Boolean, it's not necessary to compare it to "true" — you only need to name it.

     if (this.isTurn) {

Hey Johnathan, Steven,

Thank you both for your responses, that does help.