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

Eric Vandenberg
Eric Vandenberg
9,095 Points

Can't define a variable in Sublime

When defining a var in workspaces it will automatically highlight by the name of the var I am trying to establish (which is: taskInput).... for example: Imgur

When I try and define that same variable in Sublime text, the var name is not recognized and remains unhighlighted (white when it should be green).....see: top-middleColumn code Imgur. Why is this?

8 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

"But why would taskInput and incompleteTasksHolder and completedTasksHolder all be undefined?"

Try this (either within the Dev Tools in the browser once your page has loaded or somewhere in the file after they have been declared):

console.log('taskInput is a ' + typeof taskInput);

Ideally it should say something like: taskInput is a [object] HTML Element.

Sean T. Unwin
Sean T. Unwin
28,690 Points

With the theme you are using in Sublime Text when inside a JavaScript file, green is for function names (and variables that are functions) while white is for most other variables.

Sean T. Unwin
Sean T. Unwin
28,690 Points

"I see, I need to be able to call these in the console. Should I do something like this....Imgur"

No. You were right the first time.

A variable is a variable, the color-coding is helping you see which variables are of type function (as far as your example is concerned). Although, generally speaking, it is showing which statements are functions, regardless if they are a var or a function declaration, nothing more.

Are you having trouble with the console?

Eric Vandenberg
Eric Vandenberg
9,095 Points

Yes I am, I can't call taskInput or incompleteTasksHolder etc....I keep getting the Reference Error of taskInput is not defined

Sean T. Unwin
Sean T. Unwin
28,690 Points

"I keep getting the Reference Error of addButton is not defined"

That is because it is undefined -- var addButton; has not been assigned to anything yet, i.e. it is empty.

Eric Vandenberg
Eric Vandenberg
9,095 Points
console.log('taskInput is a ' + typeof taskInput);
taskInput is a undefined 
Sean T. Unwin
Sean T. Unwin
28,690 Points

Sorry, edited my comment and posted the edited part into it's own post.

Eric Vandenberg
Eric Vandenberg
9,095 Points

I see, I need to be able to call these in the console. Should I do something like this....Imgur

Eric Vandenberg
Eric Vandenberg
9,095 Points

right addButton should be undefined. But why would taskInput and incompleteTasksHolder and completedTasksHolder all be undefined?

Eric Vandenberg
Eric Vandenberg
9,095 Points

oh wait I think its working now...is this right? It should be an object correct?

console.log('taskInput is a ' + typeof taskInput);
taskInput is a object 
Eric Vandenberg
Eric Vandenberg
9,095 Points

Awesomeness, Thanks for your help Sean!