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 trialgugulethu
6,292 PointsWhy do i keep getting Task 1 is no longer passing?
I'm doing the last code review of the JS and the DOM section. Task 1 is correct, but I keep being stopped at Task 2 for an error in task 1.
const section = document.querySelector('section');
let paragraphs = section.children;
paragraphs.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
Steven Parker
231,248 PointsYou should have gotten a hint with your error.
When you tried your loop in the challenge, the error should have included this hint: "Strict mode forbids implicit creation of global property 'g'".
So all you need to do now is add a "var" or "let" to your loop initialization clause:
for (let g = 0; g < paragraphs.length; g++ )
It worked as-is on codepen because strict mode is not enabled by default there.
gugulethu
6,292 PointsOf course, thanks so much
gugulethu
6,292 Pointsgugulethu
6,292 PointsOk so the correct code should be:
const section = document.querySelector('section'); let paragraphs = section.children;
for ( g = 0; g < paragraphs.length; g++ ) { paragraphs[g].style.color = "blue"; }
To change all the p's.
This code works on codepen. Still the same problem on Treehouse.