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: Challenge Adding the Game Logic Build the updateGameState() Method

A quick refresh

So in this case in the UpdateGameState method

the final line it's concatenating the to get the specific winner.

Can somebody explain the syntax and how it works?

this.gameOver( ${target.owner.name} wins!)

1 Answer

Steven Parker
Steven Parker
220,378 Points

Here's that line with formatting:

    this.gameOver(`${target.owner.name} wins!`);

The "gameOver" method of the current object ("this") is being called, and passed a string argument.

The argument is constructed with a template literal which includes a placeholder (enclosed with "${}") to be substituted. The substituted value is the "name" property of the "owner" object which is a property of the "target" argument that was given to this method.

Does that clear it up?