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 DOM Scripting By Example Adding and Removing Names Removing Names

can't find the issue in my code

Can anyone see any obvious problems in my code? The console is telling me "unexpected end of input" citing the last line of code.

ul.addEventListener("click", (e)=>{ if(e.target.tagName ==='BUTTON'){ const li = e.target.parentNode; const ul= li.parentNode; ul.removeChild(li);} });

Jamie Moore
Jamie Moore
3,959 Points

The error message states unexpected end of input but the code you shared doesn't reference an input so, it's hard to tell what's causing this problem. Can you share all of your code?

Jason Anders
Jason Anders
Treehouse Moderator 145,624 Points

Hi Jamie Moore

Actually, the error isn't referring to user input, but rather the Javascript code being run by the interpreter. Please see my response below for a more detailed explanation. :) :dizzy:

2 Answers

Jason Anders
Jason Anders
Treehouse Moderator 145,624 Points

Hi Ryan Wikle

"Unexpected end of input" means that there is a missing closing brace or bracket. What is happening is the Javascript engine has not come across a closing element telling it to stop the program, so it wants to keep going but has no more code to run ("end of input"), so it throws the error.

Without seeing all the code, it impossible to guess where, but usually the mistake is made when closing out a nested loop or method and forgetting or accidentally deleting the originating closing element.

You'll need to go through your code and make sure that each opening brace or bracket has a corresponding closing one. If your are using Treehouse workspaces, when you place the cursor after a brace or bracket, the editor will highlight the matching one.
Personally, if I encounter this error, I count my opening braces and/or brackets and then count the closing ones. Whichever one doesn't match up in count is the one I need to find where I missed.

Hope that helps. :) :dizzy:

Thank you it did end up being just a missing bracket.