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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 2 Solution

ken schafer
ken schafer
13,263 Points

Why isn't the html variable declared?

in the code at the bottom you have

"html = "You got " + correctAnswers + " question(s) right." print(html);"

I am wondering why it's not

"var html = "You got " + correctAnswers + " question(s) right."

2 Answers

Steven Parker
Steven Parker
229,732 Points

It would have been "best practice" to include "var" in the initialization. But unless "strict" mode is being used, new variables are implicitly created as global when it omitted, so it works either way.

If you want, you could report this as a bug to the Support staff.

ken schafer
ken schafer
13,263 Points

thanks for the quick response. I was wondering if i was making a mistake somewhere and combing through to try and find where that var was declared.

Lainey Odette
Lainey Odette
18,618 Points

Dave declared the html variable at the top of the page when he added question and answer variables. :)