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 Changing and Adding Properties

Not sure why this is not accepted

I'm supposed to set the value of isTurn to false, and for some reason (maybe this is an archaic method ) this isn't working.

changing_properties.js
const player1 = {
    name: 'Ashley',
    color: 'purple',
    isTurn: true,
    play: function(){
        if (this.isTurn) {
            console.log(`${this.name} is now playing!`);
            this.isTurn=false;
         }
    }
}

const player2 = {
    name: 'Guil',
    color: 'red',
    isTurn: false,
    play: function(){
        if (this['isTurn']) {
            console.log(`${this['name']} is now playing!`);
        }
    }
}

1 Answer

The instructions are for doing it after the existing code. So you did set the value correctly using dot notation, just in the incorrect spot.

After all the existing code, change the value for player1

/** existing code**/

yourAnswerHere (player1.isTurn = false)

Notice, the need to change from this to player1 since we are no longer in the scope of the object itself

I tried that after I tried "this" for that very reason. After being denied, I then went back to "this" because I didn't understand why that would be separated from the function.

Antti Lylander
Antti Lylander
9,686 Points
const player1 = {
    name: 'Ashley',
    color: 'purple',
    isTurn: true,
    play: function(){
        if (this.isTurn) {
            console.log(`${this.name} is now playing!`);
         }
    }
}

const player2 = {
    name: 'Guil',
    color: 'red',
    isTurn: false,
    play: function(){
        if (this['isTurn']) {
            console.log(`${this['name']} is now playing!`);
        }
    }
}
//write your answer here **************************************************