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

guarlonmirka
guarlonmirka
10,192 Points

HTML +=

I can see dave adding the follwing:

html = "You got " + correctAnswers + " question(s) right.";
html += "<h2>You got these question correct: </h2>";
html += buildlist(correct);
html += "<h2>You got these question wrong: </h2>";
html += buildlist(wrong);

Is this the only way to write it? Thanks

Ryan Foote
Ryan Foote
14,435 Points

Multiline strings in JS can be kind of messy, using the method the instructor suggests makes it a bit easier to read.

http://davidwalsh.name/multiline-javascript-strings

1 Answer

Daniel Botta
Daniel Botta
17,956 Points

You could write it like this...

html = "You got " + correctAnswers + " question(s) right." +
           "<h2>You got these question correct: </h2>" +
           buildlist(correct) +
           "<h2>You got these question wrong: </h2>" +
           buildlist(wrong);

But as Ryan said, it just looks more messy and is harder to read.