Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

No support for "yoda" expressions?

Coming from a WordPress background the coding standards prefers a "yoda" expression approach, meaning that the value you're looking for is written first and then the operator. This didn't pass in the challenge:

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

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,696 Points

Yeah, I guess they're picky. What about just the property itself, since it is boolean already?:

const player1 = {
    name: 'Ashley',
    color: 'purple',
    isTurn: true,
    play: function(){
        // write code here.
      if (this.isTurn) {}
    }
}

Because JS is a weak-type language, if the isTurn property is somehow converted to a string or integer or something by a piece of code, almost any string or integer value would evaluate to "true" in your example, right?

It would be better to check that it is for certain a boolean value of true.

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,696 Points

Hmm. My feeling is that's erring on the side of being a bit too careful at the expense of making the code more bloated. Using boolean variables by themselves in this kind of situation is pretty common. If you want strong typing, TypeScript is awesome.