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: Creating Elements

Why return listItem?

In this video, around the 7-minute mark, Andrew enters:

return listItem;

as the last line of the createNewTaskElement function. Why does this need to be written here? None of the other functions in this project have a return command explicitly written in the code like that.

Thanks, Lance

PS: Also, can anyone tell me how get my code to display properly in these questions? Someone told me to enclose my code inside "three back ticks" - I assumed he meant backslashes - but I can't seem to get it to work consistently, and it's DRIVING ME CRAZY. Explain it to me like I'm 5 years old. Thanks...

5 Answers

Timothy Smith
Timothy Smith
2,072 Points

I know this question is old, but I didn't see any constructive answers. You use return to call the fully appended list back to the function. This becomes a little more apparent in the next video. Basically this function creates a "li" element, adds a few elements inside of it and then spits it out.

Sulaiman Noh
Sulaiman Noh
14,538 Points

this course are too fast. he explaining the topic so fast that i have to replay so many time. i think i like how Dave McFarland explaining. because he will go through more specifics and more easier to understand since the student is not a pro.

To display your code you will want to use the ` character. Not a backslash. On your keyboard it should share the same key as the tilde character (~). From the Markdown Cheatsheet:

Wrap your code with 3 backticks on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.

EUREKA!

return listItem;

I thought that other person meant backslashes (D'OH!). And sometimes the interface seemed to format my code automatically, but other times not. That was making me insane. Thanks, mikes02!

Gabriel Ward
Gabriel Ward
20,222 Points

Hi Lance,

I'm still very much a learner myself at the moment, so I'm not entirely sure, but, I think that this particular variable needs

'return listItem;'

because it is new and doesn't exist on the page until now. Whereas the other things are already on the HTML markup and so already appear on the page. That's my reading of it. Hopefully someone more experienced than myself might be able to verify this for us.