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 JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 2 Solution

Simon Sporrong
Simon Sporrong
35,097 Points

What is the purpose of the buildList function?

I really don't understand that bit. The function "buildList" is never called, why is that? I also don't understand what happens to the returned value "listHTML". Please help :)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! In the video you've linked here between the times of 3:00 and 3:16 the buildList function is called not once, but twice on both lines 42 and 44. The function is defined to accept an array. The two arrays we send in (one at a time) are our arrays containing our questions that we got correct and our questions that we got incorrect. Inside the function we use concatenation with the += operator to "build up" an html string. The function is started by appending the opening tag for the ordered list. Then we loop through each item inside the array we sent in. For each item in that array we're going to append a list item containing the question we got correct or incorrect. When that part is complete we'll append a closing ordered list tag and return the resulting string to the place that it was called. And if you look on lines 42 and 44, you'll see that the returned string is appended using the += operator to the html variable. Finally, we print out the entirety of the html variable to the page.

Hope this helps, but let me know if something is unclear! :sparkles:

Simon Sporrong
Simon Sporrong
35,097 Points

Thank you so much for your reply! Yes, I see what you mean now but I still have a hard time understanding all of this. Just need repetition I guess.

Thanks again!