Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

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?

Simon Feuster
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Simon Feuster
Full Stack JavaScript Techdegree Graduate 26,208 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.