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 children

Cannot understand the inside of function

While i follow that function is javascript for but i cannot understand the inside of function e.g javascript blindTaskEvents(incompleteTaskHolder.childern[i], taskCompleted); Can someone explain to me what is going on inside the function body?

//cycle over incompleteTasksHolder ul list items
for(var i = 0; i < incompleteTasksHolder.children.length; i++) {
  //bind events to list item's children (taskCompleted)
  bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
}

I can't, but I re-posted it so it would be easier to see. Also you have "blindTaskEvents(incompleteTaskHolder.childern[i], " and it should be "bind" not "blind" that might cause a problem at some point

Ammar, I noticed your into php. What do you think of php compared to JavaScript?

John Larson I think both are good, whichever lands me a job.

"Thanks, but like my thread says, i wanted to know the inside of function."... to be clear are you asking about the for loop? or the function

blindTaskEvents(incompleteTaskHolder.childern[i], taskCompleted);

that is referenced here?

3 Answers

Kevin Korte Thanks, but like my thread says, i wanted to know the inside of function.

Joel Kraft
STAFF
Joel Kraft
Treehouse Guest Teacher

Ammar Khan, as of this video, the function bindTaskEvents has not yet been written. We are just looping over all the children of the ul and executing bindTaskEvents on them as if it were already written. In the next video(s) that function will be written and explained.

Does that answer your question?

I suppose, but i hope i get grasp on what is happening inside.

Joel Kraft
Joel Kraft
Treehouse Guest Teacher

Sorry! I hadn't realized you'd already reviewed the next video. The bindTaskEvents function is responsible for getting references to three children inside each task element (the checkbox and the two buttons), and putting event handlers on them. In other words, once bindTaskEvents has done its work, each task's edit and delete button will be able to respond to a user's mouse clicks, and the checkbox will respond to being selected and unselected.

First, bindTaskEvents locates the elements using the querySelector method, and stores each element in a variable. Then, it binds each element to a function that will run every time a user interacts with that element. In the case of the editButton element, for example, every time a user clicks on that, the function editTask will run. editTask is also known as a callback function, and it defines behavior for the editButton element on the page.

Joel, Thank you for your comment about the function: "We are just looping over all the children of the ul and executing bindTaskEvents on them as if it were already written". Because to me part of what made this particular course hard to follow was just that. Andrew had things in his mind he was going to do (brilliant people do that kind of stuff) coded them out and by the time he got to them [next video] I am so hopelessly lost that **** if I know whats going on.

Joel Kraft
Joel Kraft
Treehouse Guest Teacher

John, I understand your frustration! There are a lot of moving parts here, and we're doing our best to present them in the order that makes the most sense. We're also constantly working to improve them, and appreciate your feedback, which helps us in that regard.

This stuff isn't easy, but I hope you will stick with it! It can be rewarding once you get the hang of it. Keep asking questions in the forums if you get stuck, and, of course practice coding as much as you can!

Joel, thanks for your response. I am less than amused at my own inability to grasp this course. I'm just now realizing the breadth of what is being taught here. Right now I am just going through the code line by line not moving on to anything else till I really get it.

Joel Kraft
Joel Kraft
Treehouse Guest Teacher

Ammar Khan, did that explanation help? Do you have other questions I can help with?

John Larson I am with you, while i was quickly able to get andrew course on sql and jQuery in the time it was suppose to but i am unable to grasp this course and it make my head hurt. I think the key element missing here is andrew should have broken it more down, showing what happen after every function, instead of just writing everything down and running it in one video (that is my opinion)