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

Clara Roldan
Clara Roldan
3,074 Points

Can I print the result of the buildList() function directly, without saving it to a variable?

I have tried to:

print( buildList(correct) );

Where 'buildList()' is the function used to create the HTML for the list, and 'correct' is the array with the correct questions. But nothing prints to the page.

If I do as in the video and save everything to the html variable, and then print that variable, it works.

Can someone explain me why?

2 Answers

Dan Weru
Dan Weru
47,649 Points

Hello,
I think that depends on where you're running your code at. If you're running it on workspace console (that's is while tackling the course's tests at treehouse), there's probably nothing off with your code. Else, if you're running it on chrome's console or your terminal (if you have node installed), then there could be something wrong with your code. In this case I would assume, that the first scenario is at play ... If it's the case, don't sweat it, the test has been programmed to accept the code that passes. I hope this helps ... Regards.

Aaron Pedersen
Aaron Pedersen
5,856 Points

If you changed the document.write command as Dave showed in the previous video then that might be the reason. Try to change it back to document.write(message) and see if that works.

Aaron Pedersen
Aaron Pedersen
5,856 Points

I can't explain why it works one way and not the other, though.