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!
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
Samuel Joseph5,406 Points
How can one solve this question? I used document.getElementsByTagName('body');
Is there some alternative way that I should write this?
Matthew Long28,407 Points
You're almost right. Except, if you notice, the function is
getElementByTagName(). Elements is plural. This is a good indication that it will select a collection of elements, not just a single element. In this case, you want to select the first body, which would be the first index in this collection:
const body = document.getElementsByTagName('body');