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 trialEzekiel Elin
3,839 PointsUsage of var vs let
Would it be preferable to use let
for the temporary variables, such as the random number and the number of facts?
1 Answer
Jason Wayne
11,688 PointsNot too sure about that, using let refers the variable to be a constant. By generating a random fact number, the value of the constant will always be different. Using a var might be more appropriate.
Use let when the variable value is never changed. A good example would be setting the API Key to a constant.
Ezekiel Elin
3,839 PointsEzekiel Elin
3,839 Pointshowever, isn't the random number constant for that iteration of the code?
Jason Wayne
11,688 PointsJason Wayne
11,688 PointsThat's true. Usually the scenario is using variables instead of constants if the value is never the same.