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 trialThomas Ma
15,199 PointsAddy the pug is now one year older. Add a line of code that sets the age property to 4. Don't change the original declar
Please help me
const addy = {
animal: 'dog',
age: 3,
breed: 'pug',
};
age.unit = 4;
2 Answers
Michael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsHey Thomas, to access (and therefore read or modify) the value of an object property, you do this:
object.propertyName
So if you want to change the age
property of addy
, you would do this:
addy.age = 4;
And it's as simple as that! You can also access an object property's value with bracket notation:
addy['age'] = 4;
I hope this helps!
Duc Vo
Front End Web Development Techdegree Student 16,132 PointsThe answer is:
addy.age= 4;
Max Breunig
6,029 PointsMax Breunig
6,029 Pointsabsolutely no help
Greggar Deterville
12,263 PointsGreggar Deterville
12,263 PointsSo why isn't the following also the correct answer as taught in the lesson? When run in the console it gives the answer of 4.
const addy = { animal: 'dog', age: 3, breed: 'pug' }; const message =
Addys age is ${addy.age +1}.
; console.log(message);