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

lee allen
lee allen
7,715 Points

check see if its the players turn, create empty if statement. Cant get this pass...

trying to access the property, 'isTurn' from the if statement, but just need to create an empty if statement.

Can't get this to pass, have tried a few combos, can't see what im doing wrong..

Thanks Lee

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

        }
    }
}

2 Answers

The teacher's notes from the previous video may help

To access the value of these properties inside the method, I'll use the this keyword instead of the variable name. This way, you'll always be access the property values attached to that particular object:

const teacher = {
   firstName : "Ashley",
   lastName : "Boucher",
   printName: function(){
      console.log(this.firstName + this.lastName);
   }
}
lee allen
lee allen
7,715 Points

Ah yes thanks mate! All sorted, works now! They did say check the teachers notes and I didnt! Lesson learned, thank you!!!!