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 trialStephen Gehring
11,203 PointsI notice you use let more then var in these tutorials. It seems like var would be better? Is it better to use let?
I notice you use let more then var in these tutorials. It seems like var would be better because the variable can change? Is it better to use let?
2 Answers
Austin Woodall
5,333 PointsIf we were going to have the coordinates in our URL string be based off a persons personal location then it would make sense to use var forecastURL instead of let forecastURL.
Since this tutorial is using static values it makes sense to use constants instead of variables.
If we were going to program a dynamic weather app (something like Yahoos weather app which can store multiple locations) I think the best solution would be to store user inputs (I.E. their location) in a temporary variable (var userInputLocation = 1.2345, 2.1234) then assign that temporary variable to a constant (let locationOne = userInputLocation). The reason we use the variable as a temporary placeholder is that the location will never change once set. If the user wants to add another location they can input a new value to the variable userInputLocation (var userInputLocation) and then we assign it to the constant locationTwo (let locationTwo = userInputLocation). Another benefit to this is that if a user deletes a location we can keep that constant archived in case the user wants to bring back that location without having to re-enter its location.
Sorry I got a little wordy with this but hopefully it explains why the instructor is using constants instead of variables!
Vittorio Somaschini
33,371 PointsHello Stephen.
I do not think there is a better or a worse...
If the stuff inside does not have to change in future, you use a constant.
If it may change we use a variable.
I think this is all...
Stephen Gehring
11,203 Pointsthanks
Stephen Gehring
11,203 PointsStephen Gehring
11,203 PointsQuestion about let and scope...
Is the below pseudo code acceptable?