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 trialMartin Chaffee
Front End Web Development Techdegree Student 15,278 PointsChallenge task 2 failing: "It looks like Task 1 is no longer passing".
I don't understand what I'm doing wrong. In fact, I've written the exact same HTML and JS files in Sublime and opened them in Chrome, and they work. It's driving me crazy. Can anyone please tell me what I'm doing wrong? It's making me feel like I'm missing some fundamental concept in JS...
const section = document.getElementByTagName('section');
let paragraphs = section.children;
for (i=0; i < paragraphs.length; i+= 1) {
paragraphs[i].style.color="blue";
}
<!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>
2 Answers
Wanderson Macêdo
9,266 PointsHi Martin Chaffee, the Robertin Matkov's answer is right. Have you tested his code?
Martin Chaffee
Front End Web Development Techdegree Student 15,278 PointsYes, I sorted it out. I had "i=0" rather than "let i=0". It seems as though Sublime automatically establishes "i" as a variable, which was why the code was working on my text editor but was failing in the challenge.
Robertin Datkov
11,558 PointsRobertin Datkov
11,558 PointsGreetings Martin Chaffee, I had a look at the code and I've noticed that you misspelled the method. It's actually getElementsByTagName. Which will return an array of all 'section' elements you currently have in the DOM. So in your case, you would like to select the first one:
Hope this helps!