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: 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
229,018 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?