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

Himanshu Chopra
Himanshu Chopra
3,055 Points

Hello! Here is my working code. Feedback appreciated & also I need one help!

Can somebody tell me how can print my final output inside the div which has the id 'output'. I tried document.getElementByid('output') and tried to print it inside it but not getting the desired result. Please help me with this!

Here is the Snapshot: https://w.trhou.se/wq9w56vfjr

1 Answer

Lauren O'Brien
Lauren O'Brien
7,420 Points

Hi Himanshu,

Check out the second to last video in this section "video Build a Quiz Challenge, Part 2 Solution" it will walk you through how to accomplish what you are trying to do if I understand your post correctly.

In the tutorial, the new version of the print() function uses document.getElementById() in conjunction with .innerHTML to add your new HTML to the page at the desired location. Dave's approach in this tutorial is to build up the HTML string that the print function will apply to the page piece by piece using html += '<p> new stuff to add </p>'; and then calls the print function after your html string has been built up...

So the conditional statements in your code example should be appending content to the running html variable as opposed to calling the print function each time (which operates to replace the contents of the div each time you call it - https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML).

Hope this helps!