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 trialMarcin Kurek
9,856 PointsI don't know what im doing wrong
can't find the mistake
const player1 = {
name: 'Ashley',
color: 'purple',
isTurn: true,
play: function( ){
if (player1.isTurn){};
}
}
3 Answers
Cameron Childres
11,820 PointsHey 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.
Marcin Kurek
9,856 Pointssorry didn't do it on purpose. I was checking it on my phone and had to missclick it. Thanks a lot I solved it :)
Marcin Kurek
9,856 Pointsdo you mean sth like
const player1 = { name: 'Ashley', color: 'purple', isTurn: true, play: function(){ if(this.isTrue===true){} } }
Cameron Childres
11,820 PointsYou can just change the sixth line of your original post to
if (this.isTurn){};
Cameron Childres
11,820 PointsCameron Childres
11,820 PointsCurious about the downvote here. If there's an issue with my attempt to assist I would be interested to hear your feedback.