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 trialPeter Retvari
Full Stack JavaScript Techdegree Student 8,392 PointsDon'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>';
}
Peter Retvari
Full Stack JavaScript Techdegree Student 8,392 PointsThanks 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
ravindrareddy
10,590 Pointsravindrareddy
10,590 PointsThe 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.