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 and the DOM (Retiring) Getting a Handle on the DOM Selection Review

Fuad Muhammad
Fuad Muhammad
4,273 Points

What is the correct answer of this?

I have been typed the answer was correct, but still bummer? const body = document.getElementsByTagName('body'); It is wrong?

1 Answer

Boris Yastrebov
Boris Yastrebov
11,713 Points

As far as I see you're using getElementsByTagName() method, please notice that this method returns an array, dont forget to use bracket notation to access it . So the correct answer is:

const body = document.getElementsByTagName('body')[0]; 

Actually, document.getElementsByTagName() doesn't return an array, but returns a type pretty similar :bowtie:

It returns something like a node list. I'm not 100% sure if that's what it's called, but I'm sure that it doesn't return an array.