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 JavaScript and the DOM (Retiring) Making Changes to the DOM Styling Elements

unexpected token ')' error

const toggleList = document.getElementById('toggleList');
const listDiv = document.querySelector('.list');
const input = document.querySelector('input');
const p = document.querySelector('p.description');
const button = document.querySelector('button');

toggleList.addEventListener('click', () => {
    if () {
      listDiv.style.display = 'block';
} else {
      listDiv.style.display = 'none';
}
})

button.addEventListener('click', () => {
    p.innerHTML = input.value + ":";
});

It's happening in the if statement, I seriously have looked over this code 100 times now.

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

Your if statement is empty but it needs a conditional. You should give it a condition for when it should display the element.

I have it typed out exactly the way it is written by the instructor. What condition would I put in there? All the examples and problems we have been working out have all included empty ()

Neil McPartlin
Neil McPartlin
14,662 Points

Alex. At around 5:30 in the associated video, Guil explains how you should populate that 'if statement'.

Viewing your current code in my code editor (VSC), it literally identifies the closing bracket of your empty if statement as being problematic, which is your unexpected token ')' error.

X [js] Expression expected. (8,9)

Yeah I totally noticed that when I opened my laptop up again the next day. Thanks for hanging in there through my mental fart