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 trial

JavaScript Object-Oriented JavaScript Object Basics Filling Out the Play Method

Dont 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.

object.js
const player1 = {
    name: 'Ashley',
    color: 'purple',
    isTurn: true,
    play: function(){
        if (this.isTurn == true){};
    }
}

i've used === as well to test the condition. this just happen to be the last one that i tried.

4 Answers

Steven Parker
Steven Parker
231,275 Points

You 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.

Hi 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
Adam Beer
11,314 Points

Challenge 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
Steven Parker
231,275 Points

You don't want to delete "isTurn", that's essential to the task!

Adam Beer
Adam Beer
11,314 Points

I meant:

if (this.isTurn){}

Thanks, 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.