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 trialSpencer Renfro
Courses Plus Student 11,133 PointsI need help on the coding challenge of adding an empty if inside the play method
Inside the play method, I am to add an empty if statement that checks if it is the player's turn using dot notation. I do not see why my code is not working
const player1 = { name: 'Ashley', color: 'purple', isTurn: true, play: function(){ if(player1.isTurn === true)
}
}
const player1 = {
name: 'Ashley',
color: 'purple',
isTurn: true,
play: function(){
if(player1.isTurn === true)
}
}
2 Answers
Steven Parker
231,268 PointsThe "if" statement isn't complete yet. It should be followed by braces for the code block, even if the contents are temporarily empty.
Also, code inside an object method should not refer to the object itself by name. Instead, it should use the "this" keyword.
And while it won't cause an error, you never need to compare a Boolean value to "true", you can just test it directly.
Spencer Renfro
Courses Plus Student 11,133 PointsThank you so much for the help!!
Spencer Renfro
Courses Plus Student 11,133 PointsSpencer Renfro
Courses Plus Student 11,133 PointsThe challenge still does not accept it with curly braces, I did think that was my problem but I forgot to add that into the description. I do not think I am familiar with what you mean by the "this" keyword. I also do not understand how to test the if statement directly instead of comparing a boolean to a true or false value
Steven Parker
231,268 PointsSteven Parker
231,268 PointsThe braces are just one of several issues that must all be fixed for the challenge to pass.
The use of the "this" keyword was discussed in earlier lessons. But as it applies here, instead of using object name to refer to itself (like:
player1.isTurn
) the keyword is used instead (this.isTurn
).And testing against "true" will work, but it's not necessary: