Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript A Real World Example

Peter Retvari
seal-mask
.a{fill-rule:evenodd;}techdegree
Peter Retvari
Full Stack JavaScript Techdegree Student 8,392 Points

Don't understand generate unordered-list function and addEmployee function

Hi folks,

Could you please help? I couldn't understand how the unorderedlist functions generates the li html tags from "listitems" parameter. I got that with getJSON function we get the data from the server (checked and controlled with to possible states: resolve and reject). But after we need to generate the html and append it to our page from these to functions. BUT. I couldn't figure it out, how this 'listItems' parameter works when we call the function after ".then".

  .then(generateUnorderedList)
  .then(addEmployeesToPage)

I'm talking about these functions:

function generateUnorderedList(listItems) {
    return '<ul class="bulleted">' + listItems +  '</ul>';
}

function addEmployeesToPage(unorderedList) {
    document.getElementById('employeeList').innerHTML = unorderedList;
}

My problem is that my brain works like this way:

if I would like to call a function, let's say I call generateUnorderedList(listItems), I would write generateUnorderedList(generatListItems(employees)), because I have to pass the parameter to the function. Here we didn't use anything after "then".

I wonder if you could help, specially in this part: How the program knows from listItems parameter, that we have to use generatListItems(employees)???

function generateUnorderedList(listItems) {
    return '<ul class="bulleted">' + listItems +  '</ul>';
}

The output of generatListItems function will go as an input of generateUnorderedList and then the output of generateUnorderedList will go as an input of addEmployeesToPage.

.then will take the output of the parent function as an input.

Peter Retvari
seal-mask
.a{fill-rule:evenodd;}techdegree
Peter Retvari
Full Stack JavaScript Techdegree Student 8,392 Points

Thanks Ravin, but already know what you wrote (The output of generatListItems function will go as an input of generateUnorderedList and then the output of generateUnorderedList will go as an input of addEmployeesToPage.), j=I just simply don't understand the parameters when then calls the functions, because if you would like to create the unordered list, you need the list items as well, so you have to call the listitemgenerator function trough/from the unordered list function, right? As I remember at the beginning of the video it was like this:

listitemfunction nested in unorderedlist function