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 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
229,644 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!