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 im doing wrong

can't find the mistake

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

3 Answers

Cameron Childres
Cameron Childres
11,820 Points

Hey Marcin,

It's looking for you to use the "this" keyword to access the object.

Here's a good write up I found through a previous post:

this is used inside a function (let’s say function A) and it contains the value of the object that invokes function A. We need this to access methods and properties of the object that invokes function A, especially since we don’t always know the name of the invoking object, and sometimes there is no name to use to refer to the invoking object. Indeed, this is really just a shortcut reference for the “antecedent object”—the invoking object.

Cameron Childres
Cameron Childres
11,820 Points

Curious about the downvote here. If there's an issue with my attempt to assist I would be interested to hear your feedback.

sorry didn't do it on purpose. I was checking it on my phone and had to missclick it. Thanks a lot I solved it :)

do you mean sth like

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

Cameron Childres
Cameron Childres
11,820 Points

You can just change the sixth line of your original post to

if (this.isTurn){};