Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,403 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