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 DOM Scripting By Example Adding and Removing Names Removing Names

Nebojsa Stevanovic
Nebojsa Stevanovic
Full Stack JavaScript Techdegree Student 9,620 Points

Why function createLI(text)

function createLI(text)

Why function has to have parameter TEXT ?? and what `return li; on the end on function actually does ?? Thank you

2 Answers

Melvin Ray
Melvin Ray
Courses Plus Student 6,312 Points

Within the function that calls createLI(text), there is a const that we can use to inspect or change the list item (li) that createLI(text) creates. The parameter, text, that is passed to createLI(text) is the part of the list item that is visible on the browser. It's the "banana", say, in the following unordered list(ul). <ul> <li>apple</li> <li>banana</li> <li>orange</li> </ul>

What you see on the page is:

  • apple
  • banana
  • orange

text is the value of the input field, this is the parameter. The argument will be each individual input received, it is also the name given to a list item (li) via textContent property. The function we created is to create a list item, the parameter is text, the input value that is used to name the 'li' item.

functions always return a value, a function that lacks an explicit return statement will return undefined

A function in JavaScript is similar to a procedure—a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions