Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Homeworks 10 & 11 #47

wants to merge 3 commits into from

Conversation

alexhollender
Copy link
Contributor

No description provided.

'use strict';

var weatherData = {};
weatherData.apikey = "c78fdc82343747fbafa21a15424b715b";
Copy link
Owner

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;
Copy link
Owner

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);
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants