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

I don't know what I am doing wrong here. Question is asking me to write an if statement inside a method of an object

I have done what it has asked and it still gives me an incorrect

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

Hi, Bec Asmar ,

I'm a bit of a beginner here, too, so take this with a grain of salt, but from what I can see you've almost got it! You've correctly used dot notation to access the "isTurn" key of the "player1" object. Now you just need to add the equality operator and boolean after it (but still within the parentheses) to check the value of the "isTurn" key. I hope that makes sense! If not, maybe someone else will have a better explanation!

1 Answer

Jamie Moore
Jamie Moore
3,959 Points

I solved this one today, and found the wording a little annoying. During the previous video, there's a little text box which pops up with some information about 'Object Literals Referring to Themselves' which is explained in the teachers notes.

You're doing the absolute correct thing, but the challenge is picky and wants you to use 'this', rather than 'player1' within your condition statement. To pass, it needs to read if (this.isTurn) {}.

Let me know if that works for you, and hope this helps!