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

If else help

im being told to write an empty if statment that checks if student one is suppoesed play by checking if isTurn is true but for some reason im getting an error saying unexpected end of input

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

4 Answers

Steven Parker
Steven Parker
229,644 Points

Here's a few hints:

  • when referring to instance attributes, use "this" instead of the variable name
  • a single = is an assignment operator, that's not what you need in an "if" expression
  • when testing a boolean value, you don't need to compare it to "true" — just name the value

i tried this

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

but i got unexpected identifier

Steven Parker
Steven Parker
229,644 Points

It looks like you have unbalanced braces here. And you still need to use "this" instead of the variable name.

Dimitar Dimitrov
Dimitar Dimitrov
11,800 Points

To check if condition is true you need == operator not = and i believe the challenge wants you to use the this keyword to target the object property, fix these 2 steps and you will do it

I tried this, but still no luck... I'm having the same problem as Haardik.

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

    };
}
Kostatinos Yacoumakis
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Kostatinos Yacoumakis
Full Stack JavaScript Techdegree Graduate 16,231 Points

You have a colon in the wrong spot. Try resetting the challenge and adding everything from there. You are on the right track. Remember you don't need to set a boolean value to true in an if statement. You just need to name the value by itself for it to be true, if you wanted to set it to false it would look like if(!this.isTurn){ }

i have fixed the code but am still getting

unexpected token function

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

};

}

Steven Parker
Steven Parker
229,644 Points

Haardik, I'm still seeing unbalanced braces (3 open, 2 close). And the colon after "play" seems to be missing now (I do not understand the colon comment Kostatinos made).