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

Howie Yeo
PLUS
Howie Yeo
Courses Plus Student 3,639 Points

Why didnt we use <br> to break the html code?

Hi,

Can anyone explain to me why without the use of <br> in the html variable, the code manage to break itself nicely into each questions/parts ? To my knowledge, += adds on to existing value of an variable, so it must be a long string and needs <br> at some point?

html = "You got " + correctAnswers + " question(s) right."
html += '<h2>You got these questions correct:</h2>';
html += buildList(correctGroup);
html += '<h2>You got these questions wrong:</h2>';
html += buildList(wrongGroup);
print(html);

1 Answer

this is because h tags, h1, h2 etc are block level elements by default

"Browsers typically display the block-level element with a newline both before and after the element"

https://developer.mozilla.org/en/docs/Web/HTML/Block-level_elements