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

Akshaan Mazumdar
Akshaan Mazumdar
3,747 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
Wendy Cortes
Full Stack JavaScript Techdegree Student 6,591 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.

joseph weiss
joseph weiss
4,883 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