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 Getters and Setters Setters

AJ Jhaveri
AJ Jhaveri
Full Stack JavaScript Techdegree Student 512 Points

String interpolation for setter video example not working.

I'm not getting the owner string for ${owner} in the setters oojs video example.. any ideas? syntax is the exact same as in the video. the string interpolation is not occurring for some reason.

I have:

set owner(owner) { this._owner = owner;
console.log('setter called: ${owner}'); }

but am getting the following in my console:

[after] treehouse:~/workspace$ node Pet.js
setter called: ${owner}

This works fine: console.log('setter called:' + owner); but not console.log('setter called: ${owner}'); for some reason.

3 Answers

It looks like you are using single quotes instead of backticks. The backtick key is to the left of the number 1 key.


'setter called: ${owner}'

should be this:

`setter called: ${owner}`

Here is an MDN article and a page from Stack Overflow.