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 trialKhalil Khan
4,446 PointsWhy do you add the 'return li' to the end of the function?
Why do you add the 'return li' to the end of the function?
I can't seem to get my head around the return syntax ( is it called a syntax?) Could you clarify it for me in a simple way?
Thank you!
2 Answers
Steven Parker
231,236 PointsThe "return" statement passes back the result to the caller of the function, which in this case is the event handler. This "createLI" function creates a new list item element, and it is returning that new element when it is complete.
Inside the handler, there is this code:
const li = createLI(text);
ul.appendChild(li);
So the list item that is returned is assigned to the variable "li" in the handler (same name, but different variable). The very next thing it does is to use that returned value to add the new list item to the existing list ("ul") so that it will appear on the page.
So does that help?
Maj Gajšek
Front End Web Development Techdegree Student 10,200 PointsMan I still dont get it
Mark Casavantes
Courses Plus Student 13,401 PointsMark Casavantes
Courses Plus Student 13,401 PointsHello Khalil,
Please post your code with your question. It would help us understand what you need help with.
Thank you,
Mark