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 trialJason Berry
5,180 PointsIm stuck on this question
I have tried everything around the author. I guess that I am not understanding the property in this question. const book = { title: 'Romeo and Juliet', author: 'William Shakespeare', rating: 3.74, genres: ['Classics', 'Plays', 'Fiction', 'Romance'] }
//Log the value of the author property to the console console.log(author);
4 Answers
andren
28,558 PointsTo pull out a property from an object you need to access it using dot notation or bracket notation. Like this book.author
or this book["author"]
. Just writing author
by itself will not work since that will make JavaScript look for a variable called author
.
Dot notation is the most common option, and is the one the quiz expects you to use. So the answer the quiz accepts is: book.author
Edit: When bracket notation is used you need to pass in a string. I accidentally forgot to surround the word in quotes but that has now been corrected.
Jon Lawrence
4,798 PointsWhat about console.log(this.author); ? we just had to figure out to use "this" and now its not accepted?
Heba Hendy
7,786 Points(book.author);
Welcome Julius
9,076 Pointswhat is the answer please need help
Jason Berry
5,180 PointsJason Berry
5,180 PointsThank you so much for clarifying that for me. Now I understand much better.
andren
28,558 Pointsandren
28,558 PointsGlad I could be of help. Though I have one small self correction, I just noticed that I typed
book[author]
in my post rather thanbook["author"]
. When using bracket notation you need to specify the property name using a string, so the latter is the correct syntax.Just wanted to clarify that so that it didn't lead to even more confusion in the future.