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 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,997 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!