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

Is there a bug or something because i see no error in this :(

Why isnt this working, thanks for the help

const player1 = {
    name: 'Ashley',
    color: 'purple',
    isTurn: true,
    play: function(){
        let string = this[0] +' is now playing!;
        return string;


1 Answer

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Hey Zak,

You're really close. There are just a couple of things.

  • First, there is a missing closing quote for your string.
  • Second, the instruction state to "return a string equal to the value of the name property", but for some reason you have an integer being passed into the bracket notation. I think you're trying to use an index, but the actual key name needs to be used.
    Instead of this[0], you need this["name"].

Also, just a quick tip for DRY code:
Instead of declaring a new variable and storing the concatenated string, then returning the variable. You can just return the string being concatenated.

let nameOfString = variable["keyName"] + " is going to print out a line.";
return nameOfString;

The DRY way would be:

return variable["keyName"] + " is going to print out a line.";

Both will result in identical output.

Anyway, hope that helps.
Nice work!! :) :dizzy: