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) Traversing the DOM Child Traversal

Can anyone help me with the corect code here ....

what loop ?

app.js
var section = document.querySelector('section');
var paragraphs = section.children; 
index.html
<!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>&copy; 2019</p> 
        </footer>
        <script src="app.js"></script>
    </body>
</html>

1 Answer

Hey Alexandru,

First of all great that you are learning to code. Although I do have a small recommendation for you the next time you ask a question. You need to provide more information than "What loop?". Add what the challenge ask you to do so the person helping you doesn't have to go through the challenge. Not everyone can be asked to go through the challenge just to help you, so if you could provide more information on what the challenge actually ask you to do it would be much easier :). Anyways, this challenge asks you to loop through the children elements of an UL. In this case it is the <li> tags. The easiest way and what I believe you have learned so far is the "for()" loop.

Instead of me writing you the solution I'll give you few tips this time so you could figure it out yourself(that's the best way to learn).

//an example of the for() loop

for(let i = 0; i < 10; i++){

//here goes what you want to do with the loop

};

Keep in mind that you need to use length property on the paragraph variable, so it would loop through the <li> tags. See this resource - For loop if you get stuck.

Let me know if you can't figure it out. Another good idea is to use google. As far as I know, trying to google and find solutions is a big part of becoming a developer ;).