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 Interactive Web Pages with JavaScript Selecting Elements and Adding Events with JavaScript Perform: Selecting Elements

Leah Thompson
Leah Thompson
14,997 Points

variables not defined

I'm typing along with the project in interactive javascript for web pages. At the end we are instructed to type the (supposedly now established) variable addButton. I however get an error message saying that mine is not established. I moved my code into sublime and chrome instead of workspaces, and still get the same error...therefore I've done something wrong:

//User interaction does not get desired results //add interactivity so the user can manage daily tasks

var taskInput = document.getElementById ("new-task");//new task var addButton = document.getElementsByTagName ("button)[0]; var incompleteTasksHolder = document.getElementById ("incomplete-tasks"); var completedTasksHolder= document.getElementById ("completed-tasks");

The rest of the code is the functions that aren't relevant to this particular question, but i can't see any difference in my version (above) and the video 0.o any clues?

2 Answers


Javascript is very unforgiving about how your code is formatted. In the line where you are initializing the "addButton" variable add a double quote at the end of your "button" tag. Also, remove any unnecessary spaces in the syntax. Here's what I came up with:

//Problem: User interaction doesn't provide desired results.
//Solution: Add interactivty so the user can manage daily tasks.

var taskInput = document.getElementById("new-task");

//Add a new task
var addButton = document.getElementsByTagName("button")[0];
var incompleteTasksHolder = document.getElementById("incomplete-tasks");
var completedTasksHolder = document.getElementById("completed-tasks");

I hope this helps!

Leah Thompson
Leah Thompson
14,997 Points

I forgot to put the quotes back in. Yes it was all down to formatting... and the fact that I naturally hold 'shift' when typing.... so i was trying to call things like AddButton which is never going to work. I restarted, all is solved, I hate my brain and the unforgiving nature of code lol! Thanks for such a fast response!

Happy to help!