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 Traversing and Manipulating the DOM with JavaScript Perform: Traversing Elements with querySelector

Muhammad Rizwan
Muhammad Rizwan
8,595 Points

Hi, I have question about adding function var bindTask = function(taskListItem, checkBoxEvenHandler){ }

Hi,

I have question about adding var bindTask = function(taskListItem, checkBoxEvenHandler){

}

why cannot i add at the bottom of .onclick, why should i add on top of .onclick? var bindTask = function(taskListItem, checkBoxEvenHandler){

}

addButton.onclick = addTask;

for(var i = 0; i < incompleteTasksHolder.children.length; i++){ bindTask(incompleteTasksHolder.children[i], completeTask); }

for(var i = 0; i < completeTasksHolder.children.length; i++){ bindTask(completeTasksHolder.children[i], incomTask); }

Alex Lewis
Alex Lewis
15,619 Points

If I understand you correctly, it must be added on top of the .onclick function because the variable must be declared prior to it's use.