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

Returning a property in bracket notation along with a string

I'm struggling with this coding challenge. Is it not possible to concatenate a string to a this['property'] value? For instance, according to MDN:

const Intern = { name: "Ben", age: 21, job: "Software Engineer Intern" }

function howOldAmI() { console.log('I am ' + this.age + ' years old.') }

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

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Leo Sherman ! Yes, it is possible :smiley: However, be mindful of the instructions. They are asking you to return the string. Instead, you are using a console.log(). Also, there's a space missing from your string. If you ran this, it would output "Ashleyis now playing!" instead of "Ashley is now playing!".

Hope this helps! :sparkles:

Hi Jennifer Nordell! Thanks for clarifying all of that. It completely slipped my mind to use a return statement instead of console.log( ). And thanks for the reminder about + " text" spacing! Too many late nights 😁