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

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