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

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,694 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,694 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