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

Task: Inside the play method, write an empty if statement that checks if it's the players turn. Use dot notation.

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

2 Answers

You've got pretty close to the right answer. You just need to switch isTurn and this around so it's this.isTurn (this is the object, and isTurn the property).

Thank you very much for your reply! Even when I switch it to this.isTurn, I still keep getting this error message: Bummer: Something is incorrect. Check that you wrote an if statement inside the method. Check that you're using dot notation. Are you using the this keyword?

OK, the challenge seems to be extra picky. Because isTurn is a boolean you can just use if (this.isTurn) {}. While if (this.isTurn === true) is equivalent (though redundant) it only accepts the former.

Amazing, it worked! Thank you so much. It didn't even cross my mind to leave out the "=== true".