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 trialDevjyoti Ghosh
2,422 PointsChallenge Task problem Javascript
On task it says "On line 2 of app.js, get all the paragraph elements within section and assign them to the paragraphs variable."
const section = document.querySelector('section');
let paragraphs = section.querySelectorAll('P');
It shows me this error Bummer! You didn't use the children property on the section element. I am not sure what I am doing wrong.
const section = document.querySelector('section');
let paragraphs = section.querySelectorAll('P');
<!DOCTYPE html>
<html>
<head>
<title>Child Traversal</title>
</head>
<body>
<section>
<p>This is the first paragraph</p>
<p>This is a slightly longer, second paragraph</p>
<p>Shorter, last paragraph</p>
</section>
<footer>
<p>© 2016</p>
</footer>
<script src="app.js"></script>
</body>
</html>
1 Answer
Steven Parker
231,268 PointsWell, the "Bummer" message hint tells you what they want to see, you can do it that way and pass.
But I'd recommend that you also report this as a bug to Support, as your solution should work just as well.
Devjyoti Ghosh
2,422 PointsDevjyoti Ghosh
2,422 PointsYeah Steven i got that what I am not sure on is how would i use the section's children property to select the p tags.
edit: I was able to pass the challenge by
let paragraphs = section.children;
which is not supposed to be the answer since the question is asking me to select all the paragraph elements in the section tag whereas the code selects all the dom elements under the section tag along with paragraph elements.Am I wrong in understanding the concept?
Steven Parker
231,268 PointsSteven Parker
231,268 PointsYou're right, but you're overlooking that fact that all the children of that section are paragraph elements. You can see this in the index.html file (tab).
But your original method would actually be a better choice if you wanted to make sure that only paragraphs are selected even if future HTML changes added other elements to the section.