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

TODO app javascript

var addTasks = function(){
    console.log('Task added');

  // when we add a task we need to create various elements init for that we need to use a document.createElement

       var listItem =  createElement(newTasks.value);
        incomplete.appendChild(listItem); 
        setEvent(listItem,completedTasks);

}
 // creating a new function which we're going to use for assigning a handling event to button under <ul> tag

      var setEvent = function(liItems,checkboxHandler){
           console.log('Access');
        //here we're going to use query selector to access particular item we want to access
            var checkbox = liItems.querySelector('input[type=checkbox]');
            var delt = liItems.querySelector('button.delete');
            var edit = liItems.querySelector('button.edit');

        //assigning handler

            checkbox.onchange = checkboxHandler;
            delt.onclick = deleteTasks;
            edit.onclick = editTasks;
      }

why setEvent function is assigned here ?

1 Answer

Steven Parker
Steven Parker
229,657 Points

Are you asking why is the function being assigned to a variable, instead of being declared as a named function?

It could just be programmer preference, but if your snippet leaves out this happening inside a larger declaration, it could be that it is being established as a method of that larger scope. The same considerations might also apply to addTasks.

Or did I misunderstand the question?