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 Object-Oriented JavaScript Object Basics Reviewing Object Basics

Im 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
andren
28,558 Points

To 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.

Thank you so much for clarifying that for me. Now I understand much better.

andren
andren
28,558 Points

Glad I could be of help. Though I have one small self correction, I just noticed that I typed book[author] in my post rather than book["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.

What about console.log(this.author); ? we just had to figure out to use "this" and now its not accepted?

(book.author);

what is the answer please need help