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 One Solution

Question#4 Not Working

const ul = document.querySelector('ul');
ul.style.border = "2px solid indigo";

I solved this part on my own, but it wasn't showing up on the page. When I checked the solution, I had done it exactly as the instructor had. Even after checking for formatting/spelling errors (which I am still not seeing), I am still not seeing the results like the ones from the video.

I understand that querySelector() is returning the FIRST element it finds that matches my criteria, and since the <ul> in question is the first one in the document, it should get styled, right?

Can anyone tell why this might not be working?

Cameron Childres
Cameron Childres
11,820 Points

Hi Isaac,

Your code is valid and works when I test it. It's likely that some other part of the script is getting in the way. Do you see any errors when you open up the console? If you type ul in the console does it return anything?

ReferenceError: can't access lexical declaration 'ul' before initialization

This is what the console says when I type 'ul' into it.

I think I interpreted the MDN article on this wrong. I switched the variable names to see if JS thought I was trying to call the 'ul' variable before it was ready.

const ul_var = document.querySelector('ul');
ul_var.style.border = "2px solid indigo";

This did not work either though, so I am still trying to figure out what's going on here.

1 Answer

Cameron Childres
Cameron Childres
11,820 Points

It's likely that a line of your code above these (and not the code in question) is causing an error. If a previous line errors then the lines below it will not run.

For example this will not work:

const about;
const ul = document.querySelector('ul');
ul.style.border = "2px solid indigo";

The const variable isn't initialized, causes an error, and none of the the rest of the code runs.

Look for errors elsewhere in the code and fix them (check your console for hints). If you can't find any errors then you can either comment out or delete the rest of the code besides the two lines you're working on. If it runs you'll know that somewhere the rest of your code something is wrong.

I hope this helps! If you're still stuck then please either share a workspace snapshot or post the rest of your code and I'll try and identify the problem.