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