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 Getting and Setting Text with textContent and innerHTML

Ned Redmond
Ned Redmond
5,615 Points

Code not working as typed in video!

As far as I can tell, everything in my HTML and JS files are identical to the video. However, when I copied the addEventListener function, it would not work with the final semicolon as written in the video:

p.textContent = input.value + ':';

Am I missing something? Chrome's developer tools told me that the ';' was an unexpected token, so I simply removed it to make the code work. Why does it work for the teacher and not for me? Thanks.

My code, which works:

<!DOCTYPE html>
<html>
  <head>
    <title>JavaScript and the DOM</title>
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
    <h1 id="myHeading">JavaScript and the DOM</h1>
    <p>Making a web page interactive</p>    
    <p class="description">Things that are purple:</p>
    <input class="description" type="text" />
    <button class="description">Change list description.</button>
    <ul>
      <li>grapes</li>
      <li>amethyst</li>
      <li>lavender</li>
      <li>plums</li>
    </ul>
    <script src="app.js"></script>
  </body>
</html>
const input = document.querySelector('input');
const pDesc = document.querySelector('p.description');
const button = document.querySelector('button');

button.addEventListener('click', () => (
  pDesc.textContent = input.value + ':'
                       ));

1 Answer

Steven Parker
Steven Parker
221,326 Points

The system discovered the issue when it got to the semicolon, but that's not actually the cause.

The real issue is that the statement is enclosed in parentheses () instead of braces {}.

Ned Redmond
Ned Redmond
5,615 Points

Thank you! Ugh, I keep doing this! I need to drill this bad habit out!