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

I got it to print nicely. Am I doing this the best possible way? How could I be more efficient with my code?

Here's my code: https://w.trhou.se/nisactc4ov

As you can see, it prints pretty nicely. How can I make this even cleaner? What are alternate ways of doing this that are just as clean? I want to train myself to think about several ways in which a problem can be solved, thanks!

1 Answer

Leandro Botella Penalva
Leandro Botella Penalva
17,618 Points

Hi Aditya,

You don't need to put square brackets around the string you are concatenating inside the push methods. Since you want to concatenate the question, putting square brackets around it you are creating an array and putting that array inside another array using the push method so you are creating a multidimensional array when you don't need it.

Also, if you don't want your print method to replace everything use instead the following code.

outputDiv.innerHTML += message

In this way you are concatenating to the existing HTML instead of removing what there was before.

Hope it helps.