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 trialNathaniel Lozada
4,002 PointsDo not quite know how to answer this question about objects in Javascript
The directions say that I am to- inside the play method- provide an empty 'if' statement to check if it is the player's turn, and use dot notation. However, I have no idea what these things have to do with each other, or how to use dot notation to create an if statement, or how to check for the player's turn.
Here is my code, in case it does not appear:
const player1 = {
name: 'Ashley',
color: 'purple',
isTurn: true,
play: function(){
// write code here.
}
}
1 Answer
Daniel Turato
Java Web Development Techdegree Graduate 30,124 PointsSo you need to check if its the player's turn or not. You can check this by checking if the isTurn property is set to true. Then to refrence the current context, you have to use the this keyword on isTurn. You can learn more about this here if you don't understand it fully - https://medium.com/quick-code/understanding-the-this-keyword-in-javascript-cb76d4c7c5e8 . Now for an empty if statement, it basically means you don't have to write any code in it's body. So if you do these things, you will get this:
if (this.isTurn) {
}