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 trialIsaac Hughes
3,711 PointsCant seem to figure out children background color
The error i get is that it is undefined but I cannot figure out why it does that
const section = document.querySelector('section');
let paragraphs=section.children;
for(let i=0; i< paragraphs.length; i+=1){
paragraphs.style.backgroundColor='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>
Isaac Hughes
3,711 Pointsmy problem though is trying to index it I looked back at the videos but cant seem to find it
1 Answer
Nick Rocha
7,876 Pointsdon't forget that index or i is a variable (let i = 0) just like your paragraphs variable
the index allows you to use or move the same code across the paragraphs variable like an array [p, p, p]
it should look something like: paragraphs [].style.....
Isaac Hughes
3,711 PointsI think the main issue I was having was that I was using backgroundColor instead of .color it let me pass then it mentioned something about index but I can't remember what it was, I seriously feel like smacking my forehead on the desk sometimes gahh XD
Cheo R
37,150 PointsCheo R
37,150 Pointsparagraphs.style.backgroundColor='blue';
You're close. Two things to look at: