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 JavaScript Objects Object Basics Access and Set Object Properties

Says this is wrong, not sure where I went wrong here

script.js
const addy = {
  animal: 'dog', 
  age: 3,
  breed: 'pug'
};

addy.age = ${'addy.age + 1'};

1 Answer

Cameron Childres
MOD
Cameron Childres
Treehouse Moderator 11,714 Points

Hi Kamran,

The ${} syntax is used inside template literals (strings enclosed in backticks `` instead of quotes '') to interpret code. The addy.age property holds a simple numerical value so we can work with it directly. Discard ${} as well as the quotes and the value will be accessed then the arithmetic will be carried out:

addy.age = addy.age + 1;

You can also rewrite this a number of ways without repeating addy.age:

// set property's value directly to 4
addy.age = 4; 

// add 1 to current value of property
addy.age += 1; 

// shorthand for increment by 1
addy.age++; 

Thank you so much !!!