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

Not sure what I'm missing here

I'm supposed to write an empty if statement inside play to check if it's the player's turn, and I'm obviously missing something... but can't seem to figure it out.

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

2 Answers

Alexander Lee
Alexander Lee
5,964 Points

While your solution is not incorrect,

if (this.isTurn) {}

should suffice and also seems to be the answer they're looking for here.

Thanks Alexander. I’m a little confused at why that works. Is it because that key has a Boolean value and it’s understood upon calling it?

Alexander Lee
Alexander Lee
5,964 Points

Yes, in Javascript and many other programming languages you can safely omit the ==true part altogether dealing with Booleans as it is implied.