-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Homeworks 10 & 11 #47
base: master
Are you sure you want to change the base?
Conversation
'use strict'; | ||
|
||
var weatherData = {}; | ||
weatherData.apikey = "c78fdc82343747fbafa21a15424b715b"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something we didn't cover in class, but an API key should be an environment variable that is hidden away from public repositories. This is because bots scan for keys and since a key is linked to you, they can use (and abuse!) it without penalty. Since the weather API is relatively harmless and your key is not of interest to bots, exposing it is probably fine; with other APIs you'll likely want to keep it hidden.
|
||
var weatherData = {}; | ||
weatherData.apikey = "c78fdc82343747fbafa21a15424b715b"; | ||
weatherData.url = "http://api.openweathermap.org/data/2.5/weather?q=San Francisco,CA&appid=" + weatherData.apikey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we want to check out Portland's weather? You can make your code more dynamic by abstracting away hard coded values.
"San Francisco" is a queried location in this url's API call. Allow the user to make their own location choice.
weatherData.url = "http://api.openweathermap.org/data/2.5/weather?q=" + weatherData.location + "&appid=" + weatherData.apikey;
// Work with the response | ||
success: function (r) { | ||
var degF = (r.main.temp - 273.15) * 1.8 + 32; | ||
var degFInt = Math.floor(degF); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping these two calculations separate concerns was a good call. 👍
updateWeather(); | ||
updateTime(); | ||
|
||
// This is the part that I did on my |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On yer what?
// Create a new JavaScript Date object based on the timestamp | ||
// multiplied by 1000 so that the argument is in milliseconds, not seconds. | ||
var date = new Date((r.timestamp - r.gmtOffset)*1000); | ||
// Hours part from the timestamp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stellar commenting! It really helps when other developers are reading your code.
No description provided.