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,682 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 !!!