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 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
Cameron Childres
11,817 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 !!!