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 trialAndy Durette
31,183 PointsNot sure why its not passing
I tested the code outside of the site and even changed out this.isTurn to player1.isTurn however it's not passing.
Anyone who could explain why, and what the proper format should be?
const player1 = {
name: 'Ashley',
color: 'purple',
isTurn: true,
play: function(){
// write code here.
if ( player1.isTurn === true ){
}
}
}
2 Answers
Steven Parker
231,269 PointsThe "Bummer!" message included this hint: "Are you using the this keyword?". It's not possible to reference the object by name from inside the object, so you must use "this" instead.
And it's never necessary to compare anything to "true". Anything that might have a value of "true" or "false" can be tested simply by naming it. Now in practical use, the unnecessary comparison will still work and not cause an error; but apparently the challenge doesn't allow it.
Daniel Boisselle
Front End Web Development Techdegree Student 17,438 PointsHello friend,
This is my first ever response. I would just like to say I renewed my subscription to answer your question!
Fortunately your answer is correct, as there is an issue with the compiler.
Simply change your if expression within the 'play' method to:
if (this.isTurn) { }
Cheers!
~Dan
Steven Parker
231,269 PointsI think you meant "isTurn" instead of "isTrue".
Andy Durette
31,183 PointsNoted, this and the comment by Steven Parker has cleared this up for me, amazingly you also renewed your subscription just to answer so that is appreciated.
Thanks
Daniel Boisselle
Front End Web Development Techdegree Student 17,438 PointsDaniel Boisselle
Front End Web Development Techdegree Student 17,438 PointsAh yes! Thank-you!
Also you very well can access 'player1' within the object in this case. Of course it doesn't make any practical sense in terms of modularity.
Andy Durette
31,183 PointsAndy Durette
31,183 PointsThanks for the help, I did have the this keyword however when it wasn't working I switched to the other way of targeting. Good to have further information on why that is in itself an error to do as well, I won't compare to true in future.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsI tried it out and was surprised to find that you can reference "player1" in the method (but you cannot in a property). I was expecting the creation of player1 to occur after the object literal.