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

String returned from the play method is wrong?

I feel like what I've got here should be correct, but it's telling me that the string returned isn't what it's asking for?

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

1 Answer

Bramyn Payne
Bramyn Payne
19,589 Points

Hey Beth!

I think the problem is that you have quotes around player1['name']

If you remove those you should be good. Right now it is interpreting everything inside as a string instead of finding the value that you are looking for.

Thanks Bramyn!