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 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,674 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 **************************************************