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 Basics Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Phaedra Ford
Phaedra Ford
2,643 Points

Why is Step 3 (selecting the <main> HTML element) separate from Step 6 (Output results to the <main> element)?

I remember learning to display the value of a string on a page in a previous video where only one step was used to achieve what Step 3 and Step 6 are doing.

I wrote the following code in my solution (and received no error messages): document.querySelector('main').innerHTML = Text to display

Is there a reason that it is separated into two steps in the video solution?

2 Answers

Simon Feuster
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Simon Feuster
Full Stack JavaScript Techdegree Graduate 28,036 Points

Both is right. But if you save the selected Element to a Variable you can use it again later. As your code in a realworld project will be more complex, this approach will save you some time.

Simon's answer sounds perfect. In fact, I also skipped step 3 and just wrote document.querySelector('main').innerHTML at the end once. I guess we should get used to separate things at this stage in order to make things easier later.