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

Maxwell DeMers
Maxwell DeMers
6,853 Points

Uncaught Reference Error in Console

I was following the video, and went to the console to check that my variables were selecting the correct IDs by using document.getElementById("id"). However, when I go to the console(Chrome), I get an Uncaught Reference Error. I rebuilt the variable in the console with the document.get method, and worked fine. See code below.

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

I think it may be something simple that I am not doing, but I don't see it. Please help.

Mod Note - Added backticks and language for formatting and syntax highlighting.

rydavim
rydavim
18,776 Points

I don't see anything obviously wrong with the lines you've posted. It would be helpful if you could post a workspace snapshot of your full code, and we'll see if we can't figure out what the problem is.

Maxwell DeMers
Maxwell DeMers
6,853 Points

Hey thanks rydavim. I didn't know about the workspace snapshot. See link below for snapshot.

https://w.trhou.se/drfq0dffjh

2 Answers

I know it might seem odd, but make sure that you hit refresh on the app preview itself. I was having the same issue and that fixed it for me. I have noticed that sometimes hitting the preview from Workspace doesn't always refresh the page on the app. Not sure if it's a caching problem or not, but sure seems like it.

I hope that this helps.

Maxwell DeMers
Maxwell DeMers
6,853 Points

Looks like that did it! Thanks Enrique.

rydavim
rydavim
18,776 Points

I didn't get a reference error, but it looks like you've got an extra set of closing curly braces after one the functions - taskCompleted - on about line 45. Should be good to go if you remove one. Happy coding!

var taskCompleted = function(){} // You end the function block here...

} // ...and again down here.