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 trialIvana Lescesen
19,442 PointsWhy did not he define the html?
He did not define the variable. Why not?
html = "You got " + correctAnswers + " question(s) right."
It was defined in the previous video.
Thank you for your help :)
1 Answer
Jennifer Nordell
Treehouse TeacherYou're correct. I looked at the solution file provided and he does not declare or initialize the html
variable. JavaScript is pretty smart and if the variable to be used is global (outside a function and in our main code) it can sort of figure it out itself. Remember our discussion on scope?
Take a look at this short example:
var x = 20;
y = 5;
console.log(x * y);
Now, you might suspect that this will generate an error, but it won't. It actually logs 100 to the console. Most programming languages require that you set up your variable and declare it before you use it. JavaScript is a little more forgiving. That being said, it's considered best practice to declare your variables before you use them. Hope this helps
Ivana Lescesen
19,442 PointsIvana Lescesen
19,442 PointsAMAZING as always :) Thank you :)