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 trialpauladams2
8,399 PointsSelection Review Quiz Questions:
On the quiz there is a question which asks how to select the body tag using document.getElementsByTagName and to assign it to the variable body.
They give you the start const body then an input field to put your answer. I have tried so many ways but always says wrong answer!
I put in: document.getElementsByTagName('body');
What am i doing wrong?
2 Answers
Steven Parker
231,271 PointsYou forgot to apply the index for the "zero" element.
The function returns a collection, so if you want just a single element you have to apply an index. Since there's only one "body" element, the index will be 0.
document.getElementsByTagName('body')[0]
Elizabeth Chai
9,692 PointsJust the question I was looking for. Was so confused and tried the quiz a few times...
Zachary Harriott
5,630 PointsZachary Harriott
5,630 PointsThanks! This was driving me crazy.