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 trialMark Wisdom Reeves
Full Stack JavaScript Techdegree Graduate 18,275 PointsThe for loop cycles over list items and applies a color to each item using the values stored in the colors array. For ex
var listItems; var colors = [ "#C2272D", "#F8931F", "#FFFF01", "#009245", "#0193D9", "#0C04ED", "#612F90" ];
listItems = document.querySelectorAll("#rainbow");
for(var i = 0; i < colors.length; i ++) {
listItems[i].style.color = colors[0];
}
1 Answer
Blake Larson
13,014 PointsIf the list items have a class of rainbow it should be listItems = document.querySelectorAll(".rainbow"); and if you want to have a different color for each item it should be listItems[i].style.color = colors[i]; That will work if the colors array is the same length or shorter "listItems"