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

My solution to Practice Traversing the DOM

Here's my solution!

// STARTING POINT
const list = document.querySelector('.list');

// 1: Store the first child of the `ul` in the variable `firstItem`
const firstItem = list.firstElementChild; 
firstItem.style.backgroundColor = '#04c5e6';

// 2: Using traversal, store the second list item in a variable named `nextItem`
const firstListItem = document.querySelector('li');
const nextItem =  firstListItem.parentElement.children[1];
nextItem.style.backgroundColor = '#b7c7d0';

// 3: Store the last child of the `ul` in a variable named `lastItem`
const lastItem =  list.lastElementChild;
lastItem.style.backgroundColor = '#57d6ab';

// 4: Using traversal, store the second-to-last list item in a variable named `prevItem`
const prevListItem = document.querySelector('li')
const prevItem = prevListItem.parentElement.children[2];  
prevItem.style.backgroundColor = '#f36f49';

// 5: Store the nested div in a variable named `banner`
const divBanner = document.getElementsByTagName('div')[1];
const banner = document.createElement('body');
banner.className = 'banner';
divBanner.appendChild(banner);

// 6: Using traversal, store the wrapper div in a variable named `wrapper`
const wrapperClass = document.querySelector('div');
const wrapper = wrapperClass.parentElement.children[0];
wrapper.style.backgroundColor = '#fcfcfc';

// 7: Using traversal, store the body in a variable named `body`
const bodyTag = document.querySelector('body')
const body = bodyTag.parentElement.children[0]; 
body.style.backgroundColor = '#f8fdf3';

I did my best it look almost the same as Guil, only the banner is a bit off on the corners. At least now I know that there's a simple and better solution to this kind of exercise.