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 trialKayvon Wallace
15,686 PointsDont know what wrong with this if statement
I probably put this code on the wrong line again...or something crazy, but I can't figure out what i'm doing wrong, can someone point me in the right direction.
const player1 = {
name: 'Ashley',
color: 'purple',
isTurn: true,
play: function(){
if (this.isTurn == true){};
}
}
4 Answers
Steven Parker
231,269 PointsYou never need to compare a boolean to "true". Just naming it in the test expression is enough.
Also, if you have a code block (a set of braces) after an "if", you don't need a semicolon.
I'll bet you can get it now without a code spoiler.
brevans26
15,198 PointsHi Steven Parker!
Can you tell me if I understood this statement correctly?: "You never need to compare a boolean to "true". Just naming it in the test expression is enough."
Naming in the expression is enough because the code will run if the condition is true. Otherwise we need an else
statement.
Adam Beer
11,314 PointsChallenge Task 1 of 2
Inside the play method, write an empty if statement that checks if it's the players turn. Use dot notation.
Your are very close. Delete the "isTurn" value inside the if statement, you do not need it now. Hope this help.
Steven Parker
231,269 PointsYou don't want to delete "isTurn", that's essential to the task!
Adam Beer
11,314 PointsI meant:
if (this.isTurn){}
Kayvon Wallace
15,686 PointsThanks, guys I was able to figure it out, but I'm glad I can get help so quickly. Only been doing this for about 4months, but I'm gaining steam, and ready to do this full time. need a whole lot more practice.
Warren Leyes
Front End Web Development Techdegree Graduate 31,808 Pointslol, TH pinged me 7 hours later .. glad to see you got it worked out!
Kayvon Wallace
15,686 PointsKayvon Wallace
15,686 Pointsi've used
===
as well to test the condition. this just happen to be the last one that i tried.