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

Akshaan Mazumdar
Akshaan Mazumdar
3,787 Points

Why are we using - const main = document.queryselector('main'); ? Instead can we write whole statment in the end?

Instead can we write document.queryselector('main').innerHTML(...) i.e the entire statement together in the end.

Don't really understand the importance of const main in here

2 Answers

Wendy Cortes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Wendy Cortes
Full Stack JavaScript Techdegree Graduate 16,375 Points

Hey, you are right that you can write it all together. Declaring the variable may just make it easier to understand or provide less errors in the future. If you have to use main in the future, you don't have to continue writing document.querySelector('main') each time.

josephweiss2
josephweiss2
7,657 Points

You CAN do it, Just we are looking to make it the shortest possible so if you make a variable from this main element then when ever you want to select it you just write the variable name and it selects the element