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

Interactive web pages with javascript: chapter 'Perform Selecting Elements': Getting error 'taskInput is not defined'

As it says above. My code is exactly the same as in the vid, but when I type taskInput in the console (Chrome, OS X, both latest) I get a

VM3335:1 Uncaught ReferenceError: taskInput is not defined(…)

I tried document.getElementById("new-task"); and that gets me what I want.

Halp!

Simon Coates
Simon Coates
28,688 Points

I just tried it with the workspace. It worked for me. THe only thing i can think of is that you might be running the code in a different context. I get that error is I change the context (there's a drop down box) for the page using the console (see https://developer.chrome.com/devtools/docs/console#frame-selection).

Not sure what you mean by context, but I got the code to work (w/out any changes) by copypasting it into an external editor and previewing it locally. So it seems there's something going on with your editor.

Simon Coates
Simon Coates
28,688 Points

When code executes on a different frame, variables can seem to disappear. Occasionally, the frame is set to an iframe or seems to run into complications with chrome plugins. You can see the page but there are multiple possible frames, and the code you run via the console is isolated from your page. If i switch contexts on the console (a plugin creates a second context accessible via the console tools), the variable (named x) is present and then disappears completely

x;
<input id=​"new-task" type=​"text">
x;
VM202:1 Uncaught ReferenceError: x is not defined(…)

1 Answer