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

Having problems with this task. Not sure if my dot.notation is correct

"Inside the play method, write an empty if statement that checks if it's the players turn. Use dot notation."

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

I have the same understanding as you but I don't really know what is expected. I am not really impressed with some of the treehouse questions. They are sometimes frustrating, time wasting and moral killing. Imagine spending hours trying to get answers to simple questions like this.

God bless you and your family.

19 Answers

You should use 'this' instead of 'player1' in the conditional.

Where was 'this' covered in this course, or in this js track prior to this challenge? I'm aware of it, but have no recollection of covering it in any course up until now.

Why was the ‘this’ keyword used instead of the player1?

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

God bless you and your family.

http://javascriptissexy.com/understand-javascripts-this-with-clarity-and-master-it/ Some explanations for the uses of 'this' if anyone is confused.

Thank you so much for this! console.log("You are the best");

These style of these questions are frustrating to say the least. When did you mention "this" in the last video?

Sorry for you feel fustrated with this answer, I posted from my cellphone. Here I post a link about "this" understanding the keywords. https://medium.com/quick-code/understanding-the-this-keyword-in-javascript-cb76d4c7c5e8

I had this same problem. This was my solution.

const player1 = {
    name: 'Ashley',
    color: 'purple',
    isTurn: true,
    play: function(){
       if(this.isTurn) { 
         return this.name + " is now playing!"; 
       }
    } 
}

ty Jared!

They never explained 'this' in any course. Wow this site is going down hill fast.

Thank you and God bless you and your family.

//actually, it is asking for the keyword to access the property and methods, without directly 
//accessing the literal, it is not wrong, but using the keyword is the best practice
//this keyword

const player1 = {
    name: 'Ashley',
    color: 'purple',
    isTurn: true,
    play: function(){
        // write code here.
      if (player1.isTurn) {};
    }
}
Alan McClenaghan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alan McClenaghan
Full Stack JavaScript Techdegree Graduate 56,501 Points

if (this.isTurn) {}; finally worked for me in the challenge However, if ( this.isTurn ) {}; didn't work. Don't know why it doesn't like the spaces. It worked fine in workspaces, as did using player1.isTurn as in the following example: const player1 = { name: 'Ashley', color: 'purple', isTurn: true, play: function(){ if ( player1.isTurn ) { console.log("true"); } else { console.log("false"); }; } } player1.play();

the same here. not like the space.

It's a bit silly. "This" was not covered yet that works??

Can this course lecture series cover what 'this' relates to before presenting this challenge?? The lessons didn't cover this subject yet the outcome of the challenge expected it. The only reason I had any idea this was involved was due to the error.

Oh, how I love getting the code challenge right but their own if statements to check if the questions was answered correctly only has one or 2 correct ways when in reality there are 10 ways to do this.

It's simple enough to add a few || or operators and at least half of the possible correct answers... This is just lazy.

Thanks for the assist everyone. Much appreciated.

const player1 = { name: 'Ashley', color: 'purple', isTurn: true, play: function(){ // write code here. if(this.isTurn) { return this.name + " is now playing!"; } } }

I agree with Russell and besides it didn't work. I m getting more frustrated. ?

play: function(){ // write code here. if (this.isTurn) {}; }

The last challenge is requesting bracket notation but accepts dot notation. Bit poor.

this my solutions:

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

            };
}

}

Oscar not frustrated with you. The video doesn't mention this.

Ok

Yeah for sure agree, where is 'this' used?

They never covered it. This site is going down hill. They fired most of their teachers and staff.

this "turn" situation has frustrated me as well!