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 DOM Scripting By Example Improving the Application Code Next Steps

John Barhorst
John Barhorst
9,648 Points

DOMContentLoaded Event listener prevents accessing variables in the console?

I hadn't bothered to change the HTML and app back from earlier in the project. In trying to work out some things for these challenges, I was playing in the console and found that all my variables came back as undefined. I'm not sure why I thought to change back the event listener and the script tag location, but now that I have done that I can properly access my variables.

Anyone want to shed some light on this? Everything about the app was otherwise working properly, so I'd assume that meant the DOM was fully loaded, and thus the variables should exist. Is there some scope limitation to the event listeners that prevent it from working in console? Or some sort of extra step we need to work around if, out in the wild, we have to work under a situation like this?

Thanks for your time!

Steven Parker
Steven Parker
220,768 Points

To facilitate analysis of your issue, please show your code (properly formatted with Markdown) here. Or, you can make a snapshot of your workspace and post the link to it here.